Android的按钮按下效果

    package cn.zx.android;  
      
    import android.app.Activity;  
    import android.os.Bundle;  
    import android.view.KeyEvent;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.View.OnKeyListener;  
    import android.widget.Button;  
      
    public class ButtonActivity extends Activity {  
        /** Called when the activity is first created. */  
        private Button btn;  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
            btn=(Button)this.findViewById(R.id.btn);  
            btn.setOnClickListener(new OnClickListener(){  
      
                @Override  
                public void onClick(View arg0) {  
                    // TODO Auto-generated method stub  
                    System.out.println("btn pressed");  
                }  
                  
            });  
        }  
    }  

布局文件:

<?xml version="1.0" encoding="utf-8"?>  
    <selector xmlns:android="http://schemas.android.com/apk/res/android">  
        <item android:drawable="@drawable/android_pressed"  
              android:state_pressed="true" />  
        <item android:drawable="@drawable/android_focused"  
              android:state_focused="true" />  
        <item android:drawable="@drawable/android_normal" />  
    </selector>  
    <pre class="xml" name="code">    <ImageButton   
            android:layout_width="fill_parent"   
            android:layout_height="wrap_content"  
            android:background="@drawable/ic_tab_artists"  
        /></pre>  
       




你可能感兴趣的:(android,layout,Class,import,button,encoding)