Professional Documents
Culture Documents
com
www.chandanverma.com
All non-code
resources
Images
Android Manifest
www.chandanverma.com
Manifest file
www.chandanverma.com
Manifest file
Shouldnt usuall have to edit it directl ,
Eclipse can do that for you
Preferred way of creating UIs
www.chandanverma.com
www.chandanverma.com
www.chandanverma.com
10
android:text="@stri g/* a e
android:textSize="30sp
android:textAppearance="?android:attr/t
extAppearanceLarge
android:id="@+id/te t2
android:fontFamily="Arial
android:textStyle="bold
android:textColor="#aarrggbb
android:background="#aarrggbb"
www.chandanverma.com
11
SP/DP
px is one pixel.
sp is scale-independent pixels.
dp is Density-independent pixels.
sp for font sizes
dp for everything else.
www.chandanverma.com
12
www.chandanverma.com
13
android:textColor="@color/red"
You have to create the Color.xml file in the res/value folder of your project. The
code of Color.xml is
<?xml version="1.0" encoding="utf-8"?>
<color name="white">#FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
www.chandanverma.com
14
BACKGROUND COLOR:
android:background="#aabbcc
BACKGROUND IMAGE:
SAVE IMAGE(.PNG) INTO DRAWABLE FOLODER
android:background="@drawable/images"
www.chandanverma.com
15
android:layout_marginBottom= ..dp
android:layout_marginLeft= ..dp
android:layout_gravity= ..center
android:gravity= ..center
android:layout_marginTop="dp
android:layout_width=dp"
android:layout_height="dp"
www.chandanverma.com
16
findViewById();
onClick(View v);
Gettext();
Settext();
OnClickListener();
setOnClickListener();
Toast.makeText
Toast.LENGTH_LONG
show()
getApplicationContext(),
www.chandanverma.com
17
www.chandanverma.com
18
19
20
BUTTON EVENT
Button bt.
bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"hi dear", Toast.LENGTH_LONG).show();
}
});
www.chandanverma.com
21
Button bt;
TextView t;
bt=(Button)findViewById(R.id.button1);
t=(TextView)findViewById(R.id.textView1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
t.setText our string" ;
}
www.chandanverma.com
22
ImageView i;
i=(ImageView)findViewById(R.id.imageView1);
www.chandanverma.com
23
android:layout_weight="1"
android:maxLength="5"
android:inputType="number"
www.chandanverma.com
24
b=(Button)findViewById(R.id.button1);
t=(EditText)findViewById(R.id.editText1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String mystr=t.getText().toString();
Toast msg=Toast.makeText(getBaseContext(),mystr,Toast.LENGTH_LONG);
msg.show();
}
www.chandanverma.com
25
Stringbuffer
String mystr=t.getText().toString();
String result = new
StringBuffer(mystr).reverse().toString();
www.chandanverma.com
26
FOR PLUS:
27
www.chandanverma.com
28
www.chandanverma.com
29
android:textOn="Toggle button is on
setChecked(true)
setChecked(false)
isChecked()
www.chandanverma.com
30
www.chandanverma.com
31
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:textOn="yes"
android:textOff="no"
android:checked="false"/>
www.chandanverma.com
32
ToggleButton t;
Button b;
TextView et;
t=(ToggleButton) findViewById(R.id.toggleButton1);
b=(Button) findViewById(R.id.button1);
et=(TextView) findViewById(R.id.textView1);
www.chandanverma.com
33
34
www.chandanverma.com
35
www.chandanverma.com
36
3. Implements OnClickListener
public class Radio1Activity extends Activity implements
OnClickListener{
www.chandanverma.com
37
www.chandanverma.com
38
39
android:checked="false
android:text="@string/b"
c.setOnClickListener(this);
www.chandanverma.com
40
41
www.chandanverma.com
42
43
www.chandanverma.com
44
45
46
if (checkBox1.isChecked())
{
checkBox1.setChecked(false);
} if (checkBox2.isChecked())
{
checkBox2.setChecked(false);
}
www.chandanverma.com
47
48
Toggle Button(eg)
//String edit="";
Button btn;
EditText ed;
ToggleButton toggle;
btn = (Button)findViewById(R.id.button1);
ed = (EditText)findViewById(R.id.editText1);
toggle =
(ToggleButton)findViewById(R.id.toggleButton1);
//edits = ed.getText().toString();
www.chandanverma.com
49
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
edit = ed.getText().toString();
if(edit.equals("1")){
toggle.setTextOff("TOGGLE ON");
toggle.setChecked(true);
}
else if(edit.equals("0")){
toggle.setTextOn("TOGGLE OFF");
toggle.setChecked(false);
}
}
});
www.chandanverma.com
50
www.chandanverma.com
51
www.chandanverma.com
52
Starting activities
startActivity()
Example:
Intent i = new Intent(ac1,ac2); startActivity(i);
Intent.ACTION_VIEW
Uri.parse
www.chandanverma.com
53
54
www.chandanverma.com
55
www.chandanverma.com
56
www.chandanverma.com
57
www.chandanverma.com
58
www.chandanverma.com
59
Button go,fa,gm;
addListenerOnButton();//method
}
public void addListenerOnButton() {
gm=(Button)findViewById(R.id.button1);
go=(Button)findViewById(R.id.button2);
fa=(Button)findViewById(R.id.button3);
gm.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent bw=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.gmai.com"));
www.chandanverma.com
60
www.chandanverma.com
61
62
Button btn;
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i=new Intent(firstActivity.this,secondActivity.class);
startActivity(i);
}
});
www.chandanverma.com
63
Button b;
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
www.chandanverma.com
64
www.chandanverma.com
65