Android開發(fā)中的雜⑦雜⑧

1.沉浸式狀態(tài)欄設(shè)置

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);//導(dǎo)航欄透明
}

xml

根布局中設(shè)置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漸變色背景設(shè)置

<?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全屏設(shè)置

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.十六進制和顏色透明度對照關(guān)系

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圓角背景+陰影+內(nèi)容區(qū)漸變

<?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"設(shè)置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"

要不顯示出來的效果是一條實心的直線

11.listview點擊item字體顏色selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@color/colorWhiteFour" /> <!-- focused -->
    <item android:state_pressed="true" android:color="@color/colorOrangeTow" /> <!-- pressed -->
    <item android:state_selected="true" android:color="@color/colorOrangeTow" /> <!-- pressed -->
    <item android:color="@color/colorWhiteFour" /> <!-- default -->
</selector>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容