知乎专栏 |
目录
Color.TRANSPARENT 透明
btn=(Button)findViewById(R.id.button); btn.setTextColor(Color.WHITE); btn.setBackgroundColor(Color.TRANSPARENT);
android:keepScreenOn="true"
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="cn.netkiller.student.MainActivity" tools:visibility="invisible" android:keepScreenOn="true">
实现界面背景颜色渐变效果
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>