2.布局文件main.xml复制代码代码如下:a..." />
 手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android中的Button自定义点击效果实例代码
Android中的Button自定义点击效果实例代码
摘要:方法一1.放在drawable下的selector.xml文件复制代码代码如下:android:drawable="@drawable/te...

方法一

1.放在drawable下的selector.xml文件

复制代码 代码如下:

<android="http://schemas.android.com/apk/res/Android">

android:drawable="@drawable/temp2" />

2.布局文件main.xml

复制代码 代码如下:

<http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<android:drawableTop="@drawable/shouru"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:background="@drawable/selector"/>

方法二

1.布局文件main.xml

[code]

<http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<android:id="@+id/button"

android:drawableTop="@drawable/shouru"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:background="@drawable/temp4"/>

2.主要的java代码,实现点击效果:

复制代码 代码如下:

Button button = (Button) this.findViewById(R.id.button);

button.setOnTouchListener(new Button.OnTouchListener(){

@Override

public boolean onTouch(View v, MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_DOWN){

v.setBackgroundResource(R.drawable.temp1);

Log.i("TestAndroid Button", "MotionEvent.ACTION_DOWN");

}

else if(event.getAction() == MotionEvent.ACTION_UP){

v.setBackgroundResource(R.drawable.temp2);

Log.i("TestAndroid Button", "MotionEvent.ACTION_UP");

}

return false;

}

});

【Android中的Button自定义点击效果实例代码】相关文章:

解析在Android中为TextView增加自定义HTML标签的实现方法

Android实现TextView中文字链接的4种方式介绍及代码

android中图片翻页效果简单的实现方法

android中path的arcTo方法

解析Android中使用自定义字体的实现方法

android 自定义控件 自定义属性详细介绍

Android中的脑残设计总结

Android编程实现图标拖动效果的方法

Android通话记录备份实现代码

android 自定义Android菜单背景的代码

精品推荐
分类导航