[2015/05/16] 顶栏封装 & Android按钮按下改变颜色
2015-05-16 11:06
323 查看
顶栏封装
其实我觉得我应该。恩。顶栏。。。懒,所以随便贴个代码~
链接
↑原文
布局文件中的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/com.moplast.app" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 顶栏 --> <com.moplast.custom.TopBar android:id="@+id/topBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000" custom:leftText="返回" custom:leftTextColor="#FFFFFF" custom:leftTextSize="12sp" custom:rightText="" custom:rightTextColor="#FFFFFF" custom:rightTextSize="20sp" custom:title="我的当前位置" custom:titleTextColor="#FFFFFF" custom:titleTextSize="15sp" > </com.moplast.custom.TopBar>
Android按钮按下改变颜色
提供两种方法:第一种:手动设置
backButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { //按钮按下时更改视图 if(event.getAction() == MotionEvent.ACTION_DOWN){ backButton.setBackgroundResource(R.drawable.green_click); }//按钮松开时恢复默认视图 else if(event.getAction()==MotionEvent.ACTION_UP){ backButton.setBackgroundResource(R.drawable.green); } return false; } });
这样每个按钮都需要设置监听器,非常麻烦= =。。所以我又找了个新办法,配置文件是老大!
第二种:配置文件
按下改变颜色
↑原文来自以上。
首先,在res文件夹下新建一个文件夹drawable,这是无关分辨率的:
在下面建立一个xml文件:login_button_selector.xml(我的按钮是分颜色的。。所以我的名字是button_selector_green)
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/clr_normal" android:state_pressed="false"/> <item android:drawable="@drawable/clr_pressed" android:state_pressed="true"/> </selector>然后在value文件夹下的string.xml文件里添加:
<drawable name="clr_normal">#1BE475</drawable> <drawable name="clr_pressed">#33CC66</drawable>
最后在布局文件中为button添加:
android:background="@drawable/button_selector_green"
结束~
相关文章推荐
- Android 设置圆角按下改变颜色按钮
- 1. android 设置圆角按钮后,按下按钮后,还能改变按钮的颜色
- android 中改变按钮按下时的颜色
- Android 点击按钮时改变颜色
- 改变Android按钮颜色的高效方法
- Android 设置按钮点击时候颜色背景的改变
- android 按钮按下时改变字体颜色
- Android_Button按下改变背景和字体颜色
- Android中的Button自定义点击效果之改变点击时按钮的颜色
- Android点击改变按钮颜色的3种效果
- android 在 button、textview等控件按下和选中的时候改变颜色或图片实现方法
- Android @好友解析&&改变颜色
- 关于MFC下改变buntton按下、弹起时按钮的背景颜色的问题
- Android按钮按下的时候改变颜色
- android中控制根据是否选中或者按下改变按钮的颜色(通过xml代码实现)
- Android按钮按下的时候改变颜色实现方法
- 按下按钮圆圈可以改变颜色
- 改变Android按钮背景颜色的高效方法
- 改变Android按钮背景颜色的高效方法
- android 按钮按下时改变字体颜色