知乎专栏 |
Color.TRANSPARENT 透明
btn.setBackgroundColor(Color.TRANSPARENT);
用android系统的透明效果 android:background="@android:color/transparent"
<Button android:background="@android:color/transparent" android:text="@+id/Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" />
用ARGB来控制
半透明<Button android:background="#e0000000" /> 透明<Button android:background="#00000000" />
设置alpha
View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id v.getBackground().setAlpha(100);//0~255透明度值
文本颜色 setTextColor
btn=(Button)findViewById(R.id.button); btn.setTextColor(Color.WHITE); setTextColor(this.getResources().getColor(R.color.blue)); static final int COLOR1 = Color.parseColor("#FFB032"); textview.setTextColor(COLOR1);
setBackgroundColor用法
btn.setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.parseColor("#F5F5DC")); setBackgroundColor(Color.argb(0,79,79,79)); //0完全透明 255不透明
实现界面背景颜色渐变效果
background_gradient.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--实现应用背景颜色渐变--> <gradient android:startColor="#F5736287" android:endColor="#FA7E7162" android:angle="1"/> </shape>
设置背景
android:background="@drawable/background_gradient"
android:angle 角度参数
android:angle="0" //效果是:是从左到右,按照开始颜色到结束颜色来渲染的 android:angle="90" //效果是:是从下到上,按照开始颜色到结束颜色来渲染的 android:angle="180" //效果是:是从右到左,按照开始颜色到结束颜色来渲染的 android:angle="270" //效果是:是从上到下,按照开始颜色到结束颜色来渲染的
设置圆角
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <gradient android:startColor="#00FFEA" android:endColor="#DA00FF" android:angle="45"/> <corners android:radius="10dp"/> </shape> </item> </selector>
三色渐变
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <gradient android:startColor="#FF9800" android:centerColor="#11A5E8" android:endColor="#5C00FF" android:angle="45"/> <corners android:radius="10dp"/> </shape> </item> </selector> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <gradient android:startColor="#FF9800" android:centerColor="#11A5E8" android:endColor="#5C00FF" android:angle="45"/> <corners android:radius="10dp"/> </shape> </item> </selector>