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

第 7 章 Palette 视觉设计

目录

7.1. 通用设置
7.1.1. 背景色
7.1.2. 禁止屏幕休眠
7.1.3. 渐变背景色
7.2. 样式布局
7.2.1. ConstraintLayout
7.2.2. LinearLayout
7.2.3. FrameLayout
7.2.4. 动画
7.2.5. 声音波形图
7.3. UI 界面
7.3.1. Toast
7.3.2. Dialog
7.4. Text
7.4.1. TextView
7.4.2. EditText
7.5. Button
7.5.1. 启用禁用
7.5.2. 实现 OnClickListener 接口
7.5.3. Fragment 中使用 Button
7.5.4. 圆形按钮
7.5.5. ImageButton
7.6. EditText
7.6.1. Switch
7.7. Widgets
7.7.1. ImageView
7.7.2. TextClock
7.7.3. 进度条
7.7.4. ListView
7.8. Containers
7.8.1. CardView
7.8.2. RecyclerView
7.9. Legacy
7.9.1. GardView
7.9.2. GridView
7.10. 屏幕
7.10.1. 尺寸
7.10.2. 全屏显示
7.10.3. 屏幕触摸事件 onTouch(View view, MotionEvent motionEvent)
7.10.4. 手势事件
7.10.5. SimpleOnGestureListener
7.10.6. SimpleOnScaleGestureListener

7.1. 通用设置

7.1.1. 背景色

Color.TRANSPARENT 透明

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

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

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