android各个文件分析

main.xml解析

<?xml version="1.0" encoding="utf-8"?>
version表示当前版号 encoding表示当前编码方式

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
xmlns:android 表示XML的命名空间
android:orientation 表示方向是垂直的还是水平的
android:layout_width 整个屏幕的宽度
android:layout_height 整个屏幕的高度


<TextView android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
android:id 控件的ID
android:layout_width 控件的宽度
android:layout_height 控件的高度
android:text 控件显示的默认文字
wrap_content: 控件显示的单位

 

AndroidManifese.xml解析
<?xml version="1.0" encoding="utf-8"?>
version表示当前版号
encoding表示当前的编码方式

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.misoo.ex02test"
      android:versionCode="1"
      android:versionName="1.0">

xmlns表示xml文件所在的命名空间
package表示当前android应用所在的包
android:versionCode 版本号
android:versionName 版本名称

<application android:icon="@drawable/icon" android:label="@string/app_name">
android:icon 在进入应用前所看到的程序对应的图标
android:label 在进入应用前所看到的程序对应的名称

<activity android:name=".ex02test" android:label="@string/app_name">
android:name 表示activity的名称
android:label 表示当前屏幕的标题

<intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
?????


<uses-sdk android:minSdkVersion="3" />
在androidmanifest.xml中指定最小的运行版本

 

strings.xml解析
<?xml version="1.0" encoding="utf-8"?>
version 版本号
encoding 解码方式

<string name="hello">Hello World</string>
name表示字符串的名称的ID, 这样使用 @strings/hello
Hello World 表示真正显示的字符串

 

对按纽事件处理的分析
       
//重写onCreate函数       
public void onCreate(Bundle icicle)
{
        //调用父亲的创建窗口和显示布局的函数
        super.onCreate(icicle);
        setContentView(R.layout.main);
       
        //获取布局中的两个按纽
        Button btn = (Button)findViewById(R.id.button);
        Button btn2 = (Button)findViewById(R.id.button2);
       
        //设定按纽事件的处理程序,又称为事件监听者。当使用者按下id值为btn或btn2
        //的按纽时,框架必须把事件准确地传送到适当的类(目前是当前类this),并呼叫
        //指定的函数(目前是onClick函数)
        btn.setOnClickListener(this);
        btn2.setOnClickListener(this);
       
}

//重写点击响应函数
public void onClick(View arg0)
{       
        //获取点击的控件的ID
        switch (arg0.getId())
        {
                case R.id.button:
                setTitle("this is OK button");
                break;
                case R.id.button2:
                this.finish();
                break;
        }
}


也可以这样
        public void onCreate(Bundle icicle)
        {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                ImageButton btn = (ImageButton)findViewById(R.id.button);
                ImageButton btn2 = (ImageButton)findViewById(R.id.button2);
               
                MyOnClickListener sOnClickListener = new MyOnClickListener();
                btn.setOnClickListener(sOnClickListener);
                btn2.setOnClickListener(sOnClickListener);
        }


public class MyOnClickListener extends Activity implements OnClickListener{

        public void onClick(View arg0)
        {
                switch (arg0.getId())
                {
                        case R.id.button:
                        {
                                int i = 1;
                                int j = 2;
                                int k = 0;
                                k = i + j;
                                setTitle("this is OK button");
                                break;                               
                        }

                        case R.id.button2:
                        {
                                this.finish();
                                break;                               
                        }

                }
        }
       
}

也可以这样
        public void onCreate(Bundle icicle)
        {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                ImageButton btn = (ImageButton)findViewById(R.id.button);
                ImageButton btn2 = (ImageButton)findViewById(R.id.button2);
               
                btn.setOnClickListener(listener);
                btn2.setOnClickListener(listener);
        }
       

        OnClickListener listener = new OnClickListener()
        {
                public void onClick(View v) {
                        int i = 1;
                        int j = 2;
                        int k = 0;
                        k = i + j;
                        setTitle("this is OK button");
                }
        };
       
        OnClickListener listener2 = new OnClickListener()
        {
                public void onClick(View v)
                {
                        finish();
                }
        };

 

按纽背景
方法一
Button btn = (Button)findViewById(R.id.button);
btn.setBackgroundResource(R.drawable.icon);


方法二
<ImageButton android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ok"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值