Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 116 章 Palette 视觉设计

目录

116.1. 通用设置
116.1.1. 背景色
116.1.2. 禁止屏幕休眠
116.1.3. 渐变背景色
116.2. 样式布局
116.2.1. ConstraintLayout
116.2.2. LinearLayout
116.2.3. FrameLayout
116.2.4. 动画
116.2.5. 声音波形图
116.3. UI 界面
116.3.1. Toast
116.3.2. Dialog
116.4. Text
116.4.1. TextView
116.4.2. EditText
116.5. Button
116.5.1. 启用禁用
116.5.2. 实现 OnClickListener 接口
116.5.3. Fragment 中使用 Button
116.5.4. 圆形按钮
116.6. ImageButton
116.6.1. 触摸事件
116.7. EditText
116.7.1. Switch
116.8. Widgets
116.8.1. ImageView
116.8.2. TextClock
116.8.3. 进度条
116.8.4. ListView
116.9. Containers
116.9.1. CardView
116.9.2. RecyclerView
116.10. Legacy
116.10.1. GardView
116.10.2. GridView
116.11. 屏幕
116.11.1. 尺寸
116.11.2. 全屏显示
116.11.3. 屏幕触摸事件 onTouch(View view, MotionEvent motionEvent)
116.11.4. 手势事件
116.11.5. SimpleOnGestureListener
116.11.6. SimpleOnScaleGestureListener

116.1. 通用设置

116.1.1. 背景色

Color.TRANSPARENT 透明

			
btn=(Button)findViewById(R.id.button);
btn.setTextColor(Color.WHITE);
btn.setBackgroundColor(Color.TRANSPARENT);			
			
			

116.1.2. 禁止屏幕休眠

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">		
		
			

116.1.3. 渐变背景色

实现界面背景颜色渐变效果

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>