.


:




:

































 

 

 

 





. , .. , , , . .

Android , XML-, -. . . . XML- res/layout . "res" "resources" (). , . , , , ..

res/layout activity_main.xml, . , XML- : . : Design Text.

.1.6.

Text.

XML- - XML-, View (TextView - View). , XML. .

Hello World . , . Hello Kitty .

, , Layouts, Widgets, Text Fields . Widgets ImageButton, . , , .

. . .

activity_main.xml. Properties, . , . , ImageButton TextView Hello World!. , , . , background. , . , , , .

Color , . FFC0CB #.

OK . .

, , RelativeLayout :

 

android:background="#ffffc0cb"

. . , .

background Project. New Resource... New Color Value.... . . , colors.xml. , strings.xml styles.xml, .

OK . :

 

android:background="@color/background_color"

. , , res/drawable-hdpi. , , .

.

, Drawable , . ImageButton src. Drawable - pinkhellokitty ( ).

, , . , .. .

onClick onClick - . , , onButtonPressed, .

. , TextView Hello, World (ID). , , . Widgets Large Text . .

- id. , @+id/textView. . , , . , . . Large Text. .

:

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/background_color"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="ru.alexanderklimov.hellokitty.MainActivity">

 

<ImageButton

android:id="@+id/imageButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:onClick="onClick"

android:src="@drawable/pinkhellokitty" />

 

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/imageButton"

android:layout_alignStart="@+id/imageButton"

android:layout_below="@+id/imageButton"

android:layout_marginTop="42dp"

android:text="Large Text"

android:textAppearance="?android:attr/textAppearanceLarge" />

 

</RelativeLayout>

"onClick" Alt + Enter

Create 'onClick(View)' in 'MainActivity'.

MainActivity .

MainActivity.java, . , . onCreate() :

 

private TextView mHelloTextView;

TextView mHelloTextView.

Enter, TextView import. , TextView .

onCreate() setContentView() :

 

mHelloTextView = (TextView)findViewById(R.id.textView); // , ?

, (Ctrl+) . . TextView , , .

.

 

public void onClick(View view) {

}

, :

 

mHelloTextView.setText("Hello Kitty!");

mHelloTextView setText() .

. , . - , XML-, .

app\build\outputs\apk APK-, ( ), .

,

 

// , ,

// , , .

 

package ru.alexanderklimov.hellokitty;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.TextView;

 

 

public class MainActivity extends Activity {

 

private TextView mHelloTextView;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

 

mHelloTextView = (TextView) findViewById(R.id.textView);

}

 

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

 

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

 

public void onClick(View view) {

mHelloTextView.setText("Hello Kitty!");

}

}

 

. Text Fields Plain Text , - . , hint -, .

 

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText"

android:layout_above="@+id/imageButton"

android:layout_centerHorizontal="true"

android:layout_marginBottom="66dp"

android:hint=" " />

MainActivity mHelloTextView:

 

private EditText mNameEditText;

onCreate():

 

mNameEditText = (EditText) findViewById(R.id.editText);

.

 

public void onClick(View view) {

if (mNameEditText.getText().length() == 0) {

mHelloTextView.setText("Hello Kitty!");

} else {

mHelloTextView.setText(", " + mNameEditText.getText());

}

}

. , - "Hello Kitty!". , . .





:


: 2016-11-24; !; : 560 |


:

:

, , 1:10
==> ...

1520 - | 1465 -


© 2015-2024 lektsii.org - -

: 0.067 .