深圳做微信网站设计/全国疫情最新数据
https://blog.csdn.net/shenggaofei/article/details/100172304中写到了TextInputLayout,下面看看EditText简单的设置显示错误信息的弹框提示:
一.基本属性:
hint | 输入框显示的提示文本 |
textColorHint | 输入框显示的提示文本的颜色 |
inputType | 限制用户的输入类型 |
capitalize | 英文大写设置 |
minLines | 最小行数 |
maxLines | 最大行数 |
SingleLine | 单行不换行 |
- android:inputType=none:普通字符。
- android:inputType=text:普通字符。
- android:inputType=textCapCharacters:字母大写。
- android:inputType=textCapWords:首字母大写。
- android:inputType=textCapSentences:仅第一个字母大写。
- android:inputType=textAutoCorrect:自动完成。
- android:inputType=textAutoComplete:自动完成。
- android:inputType=textMultiLine:多行输入。
- android:inputType=textImeMultiLine:输入法多行(如果支持)。
- android:inputType=textNoSuggestions:不提示。
- android:inputType=textUri:网址。
- android:inputType=textEmailAddress:电子邮件地址。
- android:inputType=textEmailSubject:邮件主题。
- android:inputType=textShortMessage:短讯。
- android:inputType=textLongMessage:长信息。
- android:inputType=textPersonName:人名。
- android:inputType=textPostalAddress:地址。
- android:inputType=textPassword:密码。
- android:inputType=textVisiblePassword:可见密码。
- android:inputType=textWebEditText:作为网页表单的文本。
- android:inputType=textFilter:文本筛选过滤。
- android:inputType=textPhonetic:拼音输入。
- android:inputType=number:数字。
- android:inputType=numberSigned:带符号数字格式。
- android:inputType=numberDecimal:带小数点的浮点格式。
- android:inputType=phone:拨号键盘。
- android:inputType=datetime:时间日期。
- android:inputType=date:日期键盘。
-
android:inputType=time:时间键盘。
text | 普通字符 |
textCapCharacters | 普通字符 |
none | 普通字符 |
textCapSentences | 字符串中的第一个字母大写 |
textCapWords | 字符串中的每个单词的首字母大写 |
textMultiLine | 多行输入 |
textImeMultiLine | 输入法多行 |
textUri | 格式为:URI |
textShortMessage | 格式为:短消息 |
textShortMessage | 格式为:长消息 |
textEmailAddress | 格式为:电子邮件地址 |
textEmailSubject | 格式为:邮件主题 |
textPostalAddress | 格式为:邮政 |
textPersonName | 格式为:姓名 |
textPassword | 格式为:不可见密码 |
textVisiblePassword | 格式为:可见密码 |
textFilter | 格式为:文本筛选 |
textWebEditText | 格式为:作为网页表单的文本 |
number | 格式为:数字 |
numberSigned | 格式为:有符号数字 |
numberDecimal | 格式为:浮点数 |
textPhonetic | 格式为:拼音输入 |
phone | 键盘为:拨号 |
date或者datetime | 键盘为:日期 |
time | 键盘为:时间 |
textAutoCorrect | 前两个自动完成 |
textAutoComplete | 前两个自动完成 |
textNoSuggestions | 不进行提示 |
EditText还派生了如下两个子类。
- AutoCompleteTextView:带有自动完成功能的EditText。由于该类通常需要与 Adapter结合使用,因此将会在下一章进行学习。
-
ExtractEditText:并不是UI组件,而是EditText组件的底层服务类,负责提供全屏输入法支持。
二.效果代码:
1.主函数:
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;import com.example.qd.douyinwu.R;
import com.example.qd.douyinwu.utils.TelNumMatch;import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** https://blog.csdn.net/shenggaofei/article/details/100172304*/
public class TextInputLayoutActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {private EditText et_one,et_two,et_three,et_four,et_type_one_b,et_type_one_a,et_type_two_a,et_type_two_b;private Button btn_registered,btn_login,bt_send,btn_cancel,btn_save;private CheckBox cb_select,cb_two,cb_one;private RadioGroup rgSex;private String sex;// 性别@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_textinputlayout);et_one = findViewById(R.id.et_one);et_two = findViewById(R.id.et_two);et_three = findViewById(R.id.et_three);et_four = findViewById(R.id.et_four);btn_registered = findViewById(R.id.btn_registered);btn_login = findViewById(R.id.btn_login);bt_send = findViewById(R.id.bt_send);btn_save = findViewById(R.id.btn_save);btn_cancel = findViewById(R.id.btn_cancel);cb_select = findViewById(R.id.cb_select);rgSex = findViewById(R.id.rgSex);// 绑定事件rgSex.setOnCheckedChangeListener(this);final Drawable dr = getResources().getDrawable(R.drawable.ic_launcher_background);dr.setBounds(0, 0, 10, 10); //必须设置大小,否则不显示cb_one = (CheckBox) findViewById(R.id.cb_one);cb_two = (CheckBox) findViewById(R.id.cb_two);et_type_one_a = findViewById(R.id.et_type_one_a);et_type_one_b = findViewById(R.id.et_type_one_b);et_type_two_a = findViewById(R.id.et_type_two_a);et_type_two_b = findViewById(R.id.et_type_two_b);et_type_one_a.setEnabled(false);et_type_one_b.setEnabled(false);et_type_two_a.setEnabled(false);et_type_two_b.setEnabled(false);//监听选中取消事件cb_one.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if (isChecked){et_type_one_a.setEnabled(true);et_type_one_b.setEnabled(true);et_type_two_a.setEnabled(false);et_type_two_b.setEnabled(false);et_type_one_a.setText("");et_type_one_b.setText("");et_type_two_a.setText("");et_type_two_b.setText("");cb_one.setChecked(true);cb_two.setChecked(false);}else {cb_one.setChecked(false);et_type_one_a.setEnabled(false);et_type_one_b.setEnabled(false);et_type_two_a.setEnabled(true);et_type_two_b.setEnabled(true);et_type_one_a.setText("");et_type_one_b.setText("");et_type_two_a.setText("");et_type_two_b.setText("");}}});cb_two.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if (isChecked){et_type_one_a.setEnabled(false);et_type_one_b.setEnabled(false);et_type_two_a.setEnabled(true);et_type_two_b.setEnabled(true);et_type_one_a.setText("");et_type_one_b.setText("");et_type_two_a.setText("");et_type_two_b.setText("");cb_two.setChecked(true);cb_one.setChecked(false);}else {et_type_one_a.setEnabled(true);et_type_one_b.setEnabled(true);et_type_two_a.setEnabled(false);et_type_two_b.setEnabled(false);et_type_one_a.setText("");et_type_one_b.setText("");et_type_two_a.setText("");et_type_two_b.setText("");cb_two.setChecked(false);}}});cb_select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){//如果选中,显示密码et_two.setTransformationMethod(HideReturnsTransformationMethod.getInstance());if(!TextUtils.isEmpty(et_two.getText().toString())){et_two.setSelection(et_two.length());}}else{//否则隐藏密码et_two.setTransformationMethod(PasswordTransformationMethod.getInstance());if(!TextUtils.isEmpty(et_two.getText().toString())){et_two.setSelection(et_two.length());}}}});btn_registered.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(TextInputLayoutActivity.this,"Registered",Toast.LENGTH_SHORT).show();}});btn_login.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(TextInputLayoutActivity.this,"Registered",Toast.LENGTH_SHORT).show();}});bt_send.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(TextInputLayoutActivity.this,"Send",Toast.LENGTH_SHORT).show();}});//注意该方法需要通过敲击回车键才会有所监听返回et_one.setOnEditorActionListener(new TextView.OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {Toast.makeText(TextInputLayoutActivity.this,"你点击了回车键了?",Toast.LENGTH_SHORT).show();return false;}});et_four.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) {String money = et_four.getText().toString();if(TextUtils.isEmpty(money)&&"".equals(money)){et_four.setError("请输入验证码");}else {if(money.length()==6){}else {et_four.setError("请输入6位数数字验证码");}}}});et_three.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) {String money = et_three.getText().toString();if(TextUtils.isEmpty(money)&&"".equals(money)){et_three.setError("请输入内容");}else {int intMoney = Integer.parseInt(money);if(intMoney>=0&&intMoney<=256){}else {et_three.setError("请输入0`256的整数值");}}}});et_two.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) {String money = et_two.getText().toString();if(TextUtils.isEmpty(money)&&"".equals(money)){et_two.setError("请输入密码");}else {if(money.length()>=6&&money.length()<=12){}else {et_two.setError("请输入6-12位数的英文字母与数字的组合");
// Toast.makeText(TextInputLayoutActivity.this,"请输入0`256的整数值",Toast.LENGTH_SHORT).show();}}}});et_one.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void afterTextChanged(Editable s) {String money = et_one.getText().toString();
// Pattern p = Pattern.compile("[0-9]*");
// Matcher m = p.matcher(money);
// if (m.matches()) {
//
// } else {
// Toast.makeText(TextInputLayoutActivity.this,"请输入正确的缴费金额",Toast.LENGTH_SHORT).show();
// }if(TextUtils.isEmpty(money)&&"".equals(money)){et_one.setError("请输入账号");}else {
// int intMoney = Integer.parseInt(money);//判断正确手机1
// if(isMobileNO(money)){//判断正确手机2
// if(TelNumMatch.isValidPhoneNumber(money)){//判断正确手机3if(TelNumMatch.isChinaPhoneLegal(money)){}else {//电话号码格式不正确et_one.setError("请输入11位数的正确手机号");
// Toast.makeText(TextInputLayoutActivity.this,"请输入0`256的整数值",Toast.LENGTH_SHORT).show();}//设置必须是1开头的数字if (!s.toString().startsWith("1")) {et_one.setText("1");et_one.setSelection(1);}}// if (!et_one.getText().toString().matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")) {
// et_one.setError("请输入正确的邮箱地址", dr);
// }}});btn_cancel.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(TextInputLayoutActivity.this,"已经取消",Toast.LENGTH_SHORT).show();}});btn_save.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(cb_one.isChecked()){Toast.makeText(TextInputLayoutActivity.this,"选择了类型1"+et_type_one_a.getText().toString()+"--"+et_type_one_b.getText().toString(),Toast.LENGTH_SHORT).show();}else if (cb_two.isChecked()){Toast.makeText(TextInputLayoutActivity.this,"选择了类型2"+et_type_two_a.getText().toString()+"--"+et_type_two_b.getText().toString(),Toast.LENGTH_SHORT).show();}else {Toast.makeText(TextInputLayoutActivity.this,"请选择类型",Toast.LENGTH_SHORT).show();}}});}@Overridepublic void onCheckedChanged(RadioGroup radioGroup, int id) {// TODO Auto-generated method stubswitch (id) {// 选择男case R.id.rbMale:sex = "男";break;// 选择女case R.id.rbFemale:sex = "女";break;default:break;}Toast.makeText(TextInputLayoutActivity.this, sex, Toast.LENGTH_SHORT).show();}private boolean isMobileNO(String mobiles) {String telRegex = "^((1[3,5,7,8][0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";if (TextUtils.isEmpty(mobiles)) {return false;} else {return mobiles.matches(telRegex);}}
}
2.布局代码及相关背景设置:
主函数布局:
<?xml version="1.0" encoding="utf-8"?><!-- xmlns:app="http://schemas.android.com/apk/res-auto" 记得设置命名空间-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!--</android.support.design.widget.TextInputLayout>--><EditTextandroid:id="@+id/et_one"android:layout_width="match_parent"android:layout_height="45dp"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:layout_marginTop="15dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入账号"android:inputType="phone"android:maxLength="11"android:paddingLeft="15dp"android:paddingRight="15dp"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:layout_marginTop="15dp"android:background="@drawable/shape_blue_sgf"><EditTextandroid:id="@+id/et_two"android:layout_width="match_parent"android:layout_height="45dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入密码"android:inputType="textPassword"android:maxLength="12"android:paddingLeft="15dp"android:paddingRight="15dp"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><CheckBoxandroid:id="@+id/cb_select"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="35dp"android:button="@drawable/checkbox_bg" /></RelativeLayout><EditTextandroid:id="@+id/et_three"android:layout_width="match_parent"android:layout_height="45dp"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:layout_marginTop="15dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入内容"android:inputType="number"android:maxLength="5"android:paddingLeft="15dp"android:paddingRight="15dp"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:layout_marginTop="15dp"android:background="@drawable/shape_blue_sgf"><EditTextandroid:id="@+id/et_four"android:layout_width="match_parent"android:layout_height="45dp"android:layout_centerVertical="true"android:layout_marginRight="130dp"android:background="@null"android:hint="请输入验证码"android:inputType="number"android:maxLength="6"android:paddingLeft="15dp"android:paddingRight="15dp"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><Buttonandroid:id="@+id/bt_send"android:layout_width="90dp"android:layout_height="30dp"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="15dp"android:layout_marginTop="10dp"android:background="@color/colorPrimary"android:text="发送"android:textColor="@color/white" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:layout_marginTop="@dimen/login_margin_top"android:gravity="center"><Buttonandroid:id="@+id/btn_login"android:layout_width="150dp"android:layout_height="40dp"android:layout_gravity="center"android:background="@drawable/btn_iv_drawable_select"android:text="login"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size" /><Buttonandroid:id="@+id/btn_registered"android:layout_width="150dp"android:layout_height="40dp"android:layout_gravity="center"android:layout_marginLeft="26dp"android:background="@drawable/shape_blue_sgf"android:text="registered"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size" /></LinearLayout>//<Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/colorPrimary"></View><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="类型选择:"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size" /><CheckBoxandroid:id="@+id/cb_one"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="@null"android:button="@null"android:drawableLeft="@drawable/radiobutton_icon"android:drawablePadding="8dp"android:text="类型1"android:textAllCaps="false" /><EditTextandroid:id="@+id/et_type_one_a"android:layout_width="90dp"android:layout_height="30dp"android:layout_gravity="center"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入内容"android:paddingLeft="5dp"android:paddingRight="5dp"android:singleLine="true"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><EditTextandroid:id="@+id/et_type_one_b"android:layout_width="90dp"android:layout_height="30dp"android:layout_gravity="center"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入内容"android:paddingLeft="5dp"android:paddingRight="5dp"android:singleLine="true"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="类型选择:"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size"android:visibility="invisible" /><CheckBoxandroid:id="@+id/cb_two"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="@null"android:button="@null"android:drawableLeft="@drawable/radiobutton_icon"android:drawablePadding="8dp"android:text="类型2"android:textAllCaps="false" /><EditTextandroid:id="@+id/et_type_two_a"android:layout_width="90dp"android:layout_height="30dp"android:layout_gravity="center"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入内容"android:paddingLeft="5dp"android:paddingRight="5dp"android:singleLine="true"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /><EditTextandroid:id="@+id/et_type_two_b"android:layout_width="90dp"android:layout_height="30dp"android:layout_gravity="center"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:background="@drawable/shape_blue_sgf"android:hint="请输入内容"android:paddingLeft="5dp"android:paddingRight="5dp"android:singleLine="true"android:textColor="@color/orange_500"android:textColorHint="@color/colorPrimary" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:layout_marginTop="@dimen/login_margin_top"android:gravity="center"><Buttonandroid:id="@+id/btn_save"android:layout_width="150dp"android:layout_height="40dp"android:layout_gravity="center"android:background="@drawable/shape_blue_sgf"android:text="save"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size" /><Buttonandroid:id="@+id/btn_cancel"android:layout_width="150dp"android:layout_height="40dp"android:layout_gravity="center"android:layout_marginLeft="26dp"android:background="@drawable/shape_blue_sgf"android:text="cancel"android:textAllCaps="false"android:textColor="@color/colorPrimary"android:textSize="@dimen/login_text_size" /></LinearLayout></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/colorPrimary" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="35dp"android:layout_gravity="center"><RadioGroupandroid:id="@+id/rgSex"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:orientation="horizontal"><RadioButtonandroid:id="@+id/rbMale"android:layout_marginLeft="15dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@null"android:button="@null"android:checked="true"android:drawableLeft="@drawable/radiobutton_icon"android:drawablePadding="5dp"android:text="男" /><RadioButtonandroid:id="@+id/rbFemale"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:background="@null"android:button="@null"android:drawableLeft="@drawable/radiobutton_icon"android:drawablePadding="5dp"android:text="女" /></RadioGroup></LinearLayout></LinearLayout>
</ScrollView>
背景设置:
shape_blue_sgf.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"><!--无圆角边框--><solid android:color="@android:color/white" /><!--填充的颜色--><!--描边--><strokeandroid:width="1dp"android:color="#0000FF" /><!--设置外层边线的圆角度数--><corners android:radius="8dp"></corners>
</shape>
密码设置显示隐藏按钮 checkbox_bg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><!-- 点击之后的图标 --><itemandroid:state_checked="true"android:drawable="@drawable/pw_show"/><!-- 点击之前的图标 --><itemandroid:state_checked="false"android:drawable="@drawable/pw_hide"/>
</selector>
自定义CheckBox、RadioButton背景选择 radiobutton_icon.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/icon_no" android:state_checked="false" /> <item android:drawable="@drawable/icon_yes" android:state_checked="true" />
</selector>
自定义登录按钮背景选择 btn_iv_drawable_select.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/shape_blue_sgf" android:state_pressed="false" /><item android:drawable="@drawable/shape_yellow_sgf" android:state_pressed="true"/>
</selector>
shape_yellow_sgf.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"><!--无圆角边框--><solid android:color="@android:color/white" /><!--填充的颜色--><!--描边--><strokeandroid:width="1dp"android:color="#FF0" /><!--设置外层边线的圆角度数--><corners android:radius="8dp"></corners>
</shape>