1.修改EditText的光标颜色
android:textCursorDrawable = "颜色";
在drawable文件夹中添加edit_cursor_color.xml。
<shape>
<size android:width="1dp"/>
<solid android:color="#000"/>
</shape>
2.修改dialog的按钮颜色
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
3.修改TextView的透明度
textView.getBackground().setAlpha(100); //0~255
4.输入法弹出导致布局上移的解决办法
在AndroidMainfest文件中给activity添加属性
android:windowSoftInputMode="adjustPan"
5.修改ProgressBar的颜色
android:indeterminateTint="#ccc"
6.将某个控件附在按钮上方,并能显示该控件不被按钮遮挡
android:stateListAnimator = "@null"
从5.0开始,在同一个Layout下,Button将总是位于最上层,点击时默认有阴影效果表示按下的状态,5.0以前只是变色。上方的代码则去掉阴影效果,使Button可以被正常覆盖。
7.设置渐变色
<shape>
<gradient android:startColor=""
angle="0" //0.从左到右渐变 90.从下到上 180.从上到下 270.从右到左
/>
</shape>
8.设置CheckBox选中的颜色
android:theme="@style/MyCheckBox"
<style name="myCheckBox" parent="@android:style/widget.Material.CompoundButton.CheckBox" tools:targetApi="lollipop">
<item name="android:colorControlActivated">@color/...</item>
<item name="android:colorControlNormal">@coloc/...</item>
</style>
9.防止点击多个控件
android:splitMotionEvents="false"
10.解决APP启动时白屏的问题
在style.xml中新建一个StyleTheme,设置windowBackground的颜色或背景图片,欢迎页的theme="@style/StyleTheme"。
11.给布局设置圆角
在drawable中创建linearLayout_border_radius_.xml。
<shape>
<solid android:color="xxx"/> //背景的颜色
<corners android:topLeftRadius="xxpx" //左上角的角度
android:topRightRadius="" //右上角
android:bottomRightRadius="" //右下角
android:bottomLeftRadius="" //左下角
</shape>
12.隐藏EditText的下划线
background = "@null"
13.给按钮设置圆角边框
<corner android:radius="xxxdip"/>
14.设置边框线的宽度和颜色
<stroke android:width="" android:color=""/>
15.设置点击更换按压图片
<selector>
<item android:state_pressed="true" android:drawable="按压后显示的图片"/>
<item android:state_checked="true" android:drawable=""/>
<item android:state_selected="true" android:drawable=""/>
<item android:drawable="正常图片"/>
</selector>
16.不允许EditText换行
inputType="text"
maxLines="1"
lines="1"
singleLine="true"