android xml 背景选择器selector
来源:互联网 发布:日本的偶像文化 知乎 编辑:程序博客网 时间:2024/05/24 04:48
selector是在res/drawable/下配置的xml,可以改变原来控件背景,例如button按下时的效果,对设计有不小帮助。
以button效果为例基本配置如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/button_unpressed" /> <item android:state_pressed="true" android:drawable="@drawable/button_pressed" /> </selector>
保存成selector_login_gmail.xml
可以通过设置android:state_xxx来配置不同状态下的图片背景
常用的有:
无android:state_xxx的用于设置默认背景
android:state_focused="true" 获取焦点时
android:state_pressed="true" 按下时
android:state_selected="true" 选中时
使用的时候可以对常用控件进行设置,例如用LinearLayout模拟Button
<LinearLayout android:id="@+id/login_gmail"android:layout_width="250dp"android:layout_height="wrap_content"adnroid:gravity="center_vertical"android:background="drawable/selector_login_gmail.xml"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="60dp"android:text="@string/login_gmail"android:color="@color/white"</LinearLayout>
在Activity中获取点击事件:
public class DoodleplusActivity extends Activity {ViewHolder mviewHolder;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_doodleplus);mviewHolder = new ViewHolder();mviewHolder.login_gmail_btn = (LinearLayout) findViewById(R.id.login_gmail);onButtonClickListener mbuttonClickListener = new onButtonClickListener();mviewHolder.login_gmail_btn.setOnClickListener(mbuttonClickLLinearLayout mLayout;istener);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.doodleplus, menu);return true;}class onButtonClickListener implements OnClickListener {@Overridepublic void onClick(View v) {switch(v.getId()) {case R.id.welcome_login_google:Log.w("OnClick", "login_gmail clicked!");break;}}}static class ViewHolder {LinearLayout login_gmail_btn;}}
0 0
- android xml 背景选择器selector
- 【android学习】xml之背景选择器selector
- android selector 背景选择器
- android背景选择器selector
- android selector背景选择器
- android 背景选择器selector
- android背景选择器selector
- Android-selector背景选择器
- Android背景选择器selector
- android selector背景选择器
- Android Selector 背景选择器
- android的selector,背景选择器
- android的selector,背景选择器
- Android的selector,背景选择器
- Android 的 selector--背景选择器
- Android的selector,背景选择器
- android背景选择器selector用法
- Android的selector,背景选择器
- VisionMobile:M2M生态系统的秘方(3):二、爆发式增长的源泉
- 要想让控件的长宽比随着窗口大小变化而自动调整,下面两个属性必须好好领会掌握。
- [Leetcode] Binary Tree Maximum Path Sum (Java)
- 自我成才
- IOS应用开发-应用评分
- android xml 背景选择器selector
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- 想想十年后的自己
- STM32 开发环境用哪个呢?
- android错误
- java中double类型不以科学计数法表示
- jsonp学习
- 【Android 工具】Android 点9图片制作及讲解
- Linux配置SSH无密码登陆