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

第 113 章 Palette 视觉设计

目录

113.1. 通用设置
113.1.1. 背景色
113.1.2. 禁止屏幕休眠
113.1.3. 渐变背景色
113.2. 样式布局
113.2.1. ConstraintLayout
113.2.2. LinearLayout
113.2.3. FrameLayout
113.2.4. 动画
113.2.5. 声音波形图
113.3. UI 界面
113.3.1. Toast
113.3.2. Dialog
113.3.3. DatePicker
113.4. Text
113.4.1. TextView
113.4.2. EditText
113.5. Button
113.5.1. 启用禁用
113.5.2. 实现 OnClickListener 接口
113.5.3. Fragment 中使用 Button
113.5.4. 圆形按钮
113.5.5. ImageButton
113.6. EditText
113.6.1. Switch
113.7. Widgets
113.7.1. ImageView
113.7.2. TextClock
113.7.3. 进度条
113.7.4. ListView
113.8. Containers
113.8.1. CardView
113.8.2. RecyclerView
113.8.3. 底部导航
113.9. Legacy
113.9.1. GardView
113.9.2. GridView
113.10. 屏幕
113.10.1. 尺寸
113.10.2. 全屏显示
113.10.3. 屏幕触摸事件 onTouch(View view, MotionEvent motionEvent)
113.10.4. 手势事件
113.10.5. SimpleOnGestureListener
113.10.6. SimpleOnScaleGestureListener
113.11. 带有小三角指示的消息框
113.11.1. 左侧三角
113.11.2. 右侧三角
113.11.3. 正三角
113.11.4. 倒三角
113.11.5. 文本边框
113.11.6. 布局

113.1. 通用设置

113.1.1. 背景色

Color.TRANSPARENT 透明

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

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

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