android开发知识点1——按钮效果
android中控件的背景或ImageView、ImageButton的资源包括字体颜色都可以通过一个xml来定义,它是一个selector,定义了在各种状态下所显示的资源,如在正常情况下,按住状态下,选择状态下,获得或失去焦点状态下等。我们的手机是有默认的按钮效果的,但是也许我们觉得它不好看,或与我们的应用的UI不搭,这时,我们就可以通过selector,来自定义按钮的按下效果等,提高用户体验。
我的习惯是,资源一般放在drawable-hdpi,drawable-mdpi,drawable-ldpi这三个文件夹中,而对于定义selector的文件,则在res下新建一个drawable文件夹并放在里面。
该selector代码如下:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_green_selected" android:state_pressed="true"/> <item android:drawable="@drawable/btn_green_normal"/></selector>
android:state_active="" android:state_checkable="" android:state_checked="" android:state_first="" android:state_enabled="" android:state_focused=" " android:state_last="" android:state_middle="" android:state_pressed="" android:state_selected="" android:state_single="true" android:state_window_focused=""

