首页 > 代码库 > Android 开发笔记___drawable

Android 开发笔记___drawable

技术分享

 

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical">
 6 
 7     <Button
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:layout_gravity="center"
11         android:layout_margin="10dp"
12         android:text="默认样式的按钮"
13         android:textColor="#000000"
14         android:textSize="17sp" />
15 
16     <Button
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"
19         android:layout_gravity="center"
20         android:layout_margin="10dp"
21         android:paddingLeft="8dp"
22         android:paddingRight="8dp"
23         android:background="@drawable/btn_nine_selector"
24         android:text="定制样式的按钮"
25         android:textColor="#000000"
26         android:textSize="17sp" />
27 
28 </LinearLayout>

selector

1 <?xml version="1.0" encoding="utf-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android">
3     <item android:state_pressed="true" android:drawable="@drawable/button_pressed" />
4     <item android:drawable="@drawable/button_normal" />
5 </selector>

java

 1 package com.example.alimjan.hello_world;
 2 
 3 import android.app.Activity;
 4 import android.content.Context;
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.support.annotation.Nullable;
 8 
 9 /**
10  * Created by alimjan on 7/1/2017.
11  */
12 
13 public class class__2_4_1_1  extends Activity {
14     @Override
15     protected void onCreate(@Nullable Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.code_2_4_1_1);
18     }
19     public static void startHome(Context mContext) {
20         Intent intent = new Intent(mContext, class__2_4_1_1.class);
21         mContext.startActivity(intent);
22     }
23 }
状态类型 说明 常用的控件
state_pressed 是否按下 按钮button
state_checked 是否勾选 单选框RadioButton、复选框chenckBox
state_focused 是否获取焦点 文本编辑框Edittext
state_selected 是否选中

各控件均可

Android 开发笔记___drawable