android Button Theme 自定义小技巧
来源:互联网 发布:淘宝网积分怎么兑换 编辑:程序博客网 时间:2024/05/21 22:29
方法一
1.放在drawable下的selector.xml文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/temp1" />
<item android:state_pressed="false" android:state_focused="false"
android:drawable="@drawable/temp2" />
<item android:state_focused="true" android:drawable="@drawable/temp3" />
<item android:state_focused="false" android:drawable="@drawable/temp4" />
</selector>
2.布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:drawableTop="@drawable/shouru"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button"
android:background="@drawable/selector"/>
</LinearLayout>
3.只是为了测试,所以效果不是很好,Button部分状态效果图如下:
①初始化的时候默认显示的按钮效果:
②点击后释放显示的效果
③点击不放时的效果
方法二
1.布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
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"/>
</LinearLayout>
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 Theme 自定义小技巧
- android 关于自定义Theme
- Android自定义Theme&style
- Android 自定义theme
- android自定义theme尝试
- android自定义theme
- android开发小技巧(1)获取EditText确定button状态
- android小技巧--shape自定义阴影效果
- android自定义控件style学习小技巧
- input Button使用小技巧
- android自定义theme的使用
- Android自定义Button组件
- android自定义button样式
- android之自定义button
- android 自定义button shape
- android 自定义BUtton
- Android自定义Button按钮
- android自定义button样式
- POJ 测试数据
- Hadoop使用常见问题以及解决方法(1)
- sql题目,统计每个班级考试成绩的合格率,优秀率
- 关于算法导论
- 套接字中的一些数据格式的转换与统一
- android Button Theme 自定义小技巧
- Hadoop使用常见问题以及解决方法(4)
- 求子数组的和最接近特定值
- Hadoop使用常见问题以及解决方法5
- 我的emacs配置
- linux下查看硬盘分区的使用情况
- 如何取消wow3.0后与服务器设置的同步(设置、键位、宏)
- 谁动了我的雨伞!!
- Python-memcached的基本使用