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.3. UI 界面
113.3.1. Toast
113.3.2. Dialog
113.3.3. DatePicker
113.4. Text
113.4.1. Text 相关属性
113.4.2. TextView
113.4.3. EditText
113.4.4. 光标移动到行尾
113.4.5. 禁止选择文本
113.4.6. 设置 app:backgroundTint
113.4.7. 禁止滚动条
113.5. Button
113.5.1. 启用禁用
113.5.2. 实现 OnClickListener 接口
113.5.3. Fragment 中使用 Button
113.5.4. 圆形按钮
113.5.5. ImageButton
113.6. Switch
113.7. Widgets
113.7.1. ImageView
113.7.2. TextClock
113.7.3. 进度条
113.8. Containers
113.8.1. CardView
113.8.2. RecyclerView
113.8.3. NavigationView
113.8.4. 底部导航
113.8.5. TabLayout
113.8.6. ViewPager2
113.9. 屏幕
113.9.1. 尺寸
113.9.2. 全屏显示
113.9.3. 屏幕触摸事件 onTouch(View view, MotionEvent motionEvent)
113.9.4. 手势事件
113.9.5. SimpleOnGestureListener
113.9.6. SimpleOnScaleGestureListener
113.10. 带有小三角指示的消息框
113.10.1. 左侧三角
113.10.2. 右侧三角
113.10.3. 正三角
113.10.4. 倒三角
113.10.5. 文本边框
113.10.6. 布局

113.1. 通用设置

113.1.1. 颜色设置

文本颜色 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不透明
			
			

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>