知乎专栏 |
editText.setEnabled(false); //禁用EditText editText.setFocusableInTouchMode(false);//不可编辑 editText.setKeyListener(null);//不可粘贴,长按不会弹出粘贴框 editText.setClickable(false);//不可点击,但是这个效果我这边没体现出来,不知道怎没用 editText.setFocusable(false);//不可编辑
圆角,胶囊形状
<TextView android:id="@+id/hotelClose" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:background="@drawable/TextViewCornerRadius" android:paddingStart="12dp" android:paddingTop="2dp" android:paddingEnd="12dp" android:paddingBottom="2dp" android:text="关闭" android:textColor="@color/white" android:textSize="16sp" />
drawable/TextViewCornerRadius.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item > <shape android:shape="rectangle"> <stroke android:width="1.5dp" android:color="@color/white" /> <solid android:color="#00000000" /> <corners android:radius="15dp" /> </shape> </item> </layer-list>
android:shadowColor: 阴影的颜色 android:shadowDx: 水平方向上的偏移量 android:shadowDy: 垂直方向上的偏移量 android:shadowRadius: 是阴影的的半径大少
设置滚动条方向 android:scrollbars="vertical",是隐藏滚动条滑块 android:fadeScrollbars="true"
<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:inputType="textMultiLine" android:padding="10dp" android:scrollbars="vertical" android:fadeScrollbars="true" android:text="按住麦克风图标说话" android:textSize="24sp" />
textView = findViewById(R.id.textView); textView.setMovementMethod(ScrollingMovementMethod.getInstance());
<EditText android:inputType="none" android:inputType="phone" //电话号码 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="datetime" //时间日期 android:inputType="date" //日期键盘 android:inputType="time" //时间键盘 />
android:editable="false" android:focusable="false" 设置不可编辑状态: editText.setFocusable(false); editText.setFocusableInTouchMode(false); 设置可编辑状态: editText.setFocusableInTouchMode(true); editText.setFocusable(true); editText.requestFocus();
临时禁止滚动条,让滚动失效
OnTouchListener 返回 true 禁止滚动
binding.recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return true; } });
OnTouchListener 返回 false 恢复滚动
binding.recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return false; } });