android 部分控件样式自定义(button例)
2012-07-03 11:24
519 查看
在android中,可以设置一个button控件各状态下的样式。
首先,在res/drawable中定义mbutton.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/btnfocused" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/btnfocusedpressed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/btnpressed" />
<item android:drawable="@drawable/btndefault" />
</selector>
然后在layout文件中使用:
<Button
...
android:background="@drawable/mbutton"
...
注意:btnfocused、btnfocusedpressed、btnpressed、btndefault这几个是button不同状态下的背景图片,放在drawable或其他几个drawable文件夹中。
效果(随便拣的几张图片):(本来有几张图片没有上传上来)
default:
focused:
pressed:
focused&pressed:
这里还有个问题,focused在pressed后消失,所以没有获取到focusedpressed样式。
首先,在res/drawable中定义mbutton.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/btnfocused" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/btnfocusedpressed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/btnpressed" />
<item android:drawable="@drawable/btndefault" />
</selector>
然后在layout文件中使用:
<Button
...
android:background="@drawable/mbutton"
...
注意:btnfocused、btnfocusedpressed、btnpressed、btndefault这几个是button不同状态下的背景图片,放在drawable或其他几个drawable文件夹中。
效果(随便拣的几张图片):(本来有几张图片没有上传上来)
default:
focused:
pressed:
focused&pressed:
这里还有个问题,focused在pressed后消失,所以没有获取到focusedpressed样式。
相关文章推荐
- Android--自定义Button的样式以及动态渐变效果
- android背景选择器selector用法、自定义Button按钮样式..........
- Android自定义Button按钮显示样式
- android-控件样式(Theme)自定义
- Android shape自定义button样式
- 更改Android AppCompatRadioButton控件的样式和颜色
- Android RatingBar 评星控件的自定义大小和样式
- Android自定义Button按钮显示样式
- android自定义button样式
- android笔记 自定义textview,button等控件的外观,点击效果
- android的Spinner控件的自定义样式设置以及ArrayAdapter的使用
- Android button自定义样式显示
- Android 自定义Button按钮显示样式(正常、按下、获取焦点)
- Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、
- Flex中自定义Alert控件按钮(Button)样式的例子
- android自定义button样式【转】 分类: Android开发 2014-05-30 10:56 35人阅读 评论(0) 收藏
- ---转Android 自定义Button按钮显示样式
- Android 自定义Button按钮显示样式(正常、按下、获取焦点)
- Android改变button等控件的样式
- Android自定义Button按钮显示样式