1.沉浸式状态栏设置
java代码
if (Build.VERSION.SDK_INT >= 21) {
View decorView = getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(option);
getWindow().setStatusBarColor(Color.TRANSPARENT);
getWindow().setNavigationBarColor(Color.TRANSPARENT);//导航栏透明
}
xml
根布局中设置fitsSystemWindows 和background
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_bg"
android:fitsSystemWindows="true"
android:orientation="vertical">
</LinearLayout>
2.xml渐变色背景设置
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 渐变色 -->
<gradient
android:angle="0"
android:endColor="#2C364C"
android:centerColor="#47607C"
android:startColor="#47607C"
/>
</shape>
3.Activity全屏设置
import android.view.WindowManager;
import android.support.v7.app.ActionBar;
/**
* hide action bar
*/
private void hideActionBar() {
// Hide UI
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
}
/**
* set the activity display in full screen
*/
private void setFullScreen() {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
4.十六进制和颜色透明度对照关系
100% — FF | 90% — E6 | 80% — CC | 70% — B3 | 60% — 99 | 50% — 80 | 40% — 66 | 30% — 4D | 20% — 33 | 10% — 1A |
---|---|---|---|---|---|---|---|---|---|
99% — FC | 89% — E3 | 79% — C9 | 69% — B0 | 59% — 96 | 49% — 7D | 39% — 63 | 29% — 4A | 19% — 30 | 9% — 17 |
98% — FA | 88% — E0 | 78% — C7 | 68% — AD | 58% — 94 | 48% — 7A | 38% — 61 | 28% — 47 | 18% — 2E | 8% — 14 |
97% — F7 | 87% — DE | 77% — C4 | 67% — AB | 57% — 91 | 47% — 78 | 37% — 5E | 27% — 45 | 17% — 2B | 7% — 12 |
96% — F5 | 86% — DB | 76% — C2 | 66% — A8 | 56% — 8F | 46% — 75 | 36% — 5C | 26% — 42 | 16% — 29 | 6% — 0F |
95% — F2 | 85% — D9 | 75% — BF | 65% — A6 | 55% — 8C | 45% — 73 | 35% — 59 | 25% — 40 | 15% — 26 | 5% — 0D |
94% — F0 | 84% — D6 | 74% — BD | 64% — A3 | 54% — 8A | 44% — 70 | 34% — 57 | 24% — 3D | 14% — 24 | 4% — 0A |
93% — ED | 83% — D4 | 73% — BA | 63% — A1 | 53% — 87 | 43% — 6E | 33% — 54 | 23% — 3B | 13% — 21 | 3% — 08 |
92% — EB | 82% — D1 | 72% — B8 | 62% — 9E | 52% — 85 | 42% — 6B | 32% — 52 | 22% — 38 | 12% — 1F | 2% — 05 |
91% — E8 | 81% — CF | 71% — B5 | 61% — 9C | 51% — 82 | 41% — 69 | 31% — 4F | 21% — 36 | 11% — 1C | 1% — 03 |
5.xml圆角背景+阴影+内容区渐变
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#4D2E364A"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item android:bottom="2dp"
android:left="0dp"
android:right="1dp"
android:top="0dp">
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#FFFFFF"
android:startColor="#C4DCF1"
/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
6.只有边框的xml shape背景图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#4591F3"/>
<corners android:radius="45dp"/>
</shape>
7.xml圆角背景+阴影渐变
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#0DC0C0C9" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#10C0C0C9" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#15C0C0C9" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="1dp"
android:left="0dp"
android:right="1dp"
android:top="0dp" />
<solid android:color="#20C0C0C9" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:bottom="1dp"
android:left="0dp"
android:right="1dp"
android:top="0dp" />
<solid android:color="#30C0C0C9" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#FFFFFF" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
8.TextView文字不居中 文本边距取消留白
添加<TextView>标签属性android:includeFontPadding="false"设置TextView文本边距取消留白
9.xml 去除<Button>自带样式
style="?android:attr/borderlessButtonStyle"
10.xml——虚线画法
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="#E6F0F8"
android:dashWidth="3dp"
android:dashGap="3dp" />
<size android:height="2dp" />
</shape>
android:width 虚线的宽度
android:dashWidth 虚线一个点点的长度(我也不知道咋描述了)
android:dashGap 虚线点点之间的距离(就这么描述吧)
最后最重要的一步,要在使用改虚线资源的布局里写一句
android:layerType="software"
要不显示出来的效果是一条实心的直线
网友评论