国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SystemBarTint實現沉浸模式

2019-11-09 18:57:18
字體:
來源:轉載
供稿:網友

先看幾張圖對比一下在不同版本的顯示效果 4.4沉浸模式: 4.4沉浸模式 6.0沉浸模式: 6.0沉浸模式 4.4狀態欄顏色: 4.4狀態欄顏色 6.0狀態欄顏色: 6.0狀態欄顏色 下面看實現過程: 首先去github上下載SystemBarTint源碼 SystemBarTint 下載后發現其中只有一個關鍵類SystemBarTintManager,將它復制到自己的項目中。 修改SystemBarTintManager類中DEFAULT_TINT_COLOR的值,這個是默認添加在狀態欄位置的布局的顏色

/** * The default system bar tint color value. */ // 將顏色變為透明public static final int DEFAULT_TINT_COLOR = 0x00000000;

styles.xml代碼

<resources> <!-- Base application theme. --> <style name="A定義Activity樣式

<activity android:name=".ActionbarActivity" android:theme="@style/ActionBarTheme"></activity><activity android:name=".FullscreenActivity" android:theme="@style/FullBleedTheme"></activity>

沉浸模式Activity代碼

public class FullscreenActivity extends AppCompatActivity{ @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fullscreen); Toolbar myToolbar = (Toolbar) findViewById(R.id.toolBar); setSupportActionBar(myToolbar); // create our manager instance after the content view is set SystemBarTintManager tintManager = new SystemBarTintManager(this); // enable status bar tint tintManager.setStatusBarTintEnabled(true); // enable navigation bar tint tintManager.setNavigationBarTintEnabled(true); }}

設置狀態欄顏色代碼

public class ActionbarActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fullscreen); Toolbar myToolbar = (Toolbar) findViewById(R.id.toolBar); setSupportActionBar(myToolbar); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); } SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.colorPrimary); } @TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }}

總結:SystemBarTint在4.4跟6.0的沉浸模式效果還不錯,同時能夠修改4.4系統的狀態欄顏色,不過在6.0的手機上修改狀態欄顏色效果不是太好(可以在主題中直接修改狀態欄顏色)。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大邑县| 孝昌县| 郴州市| 德化县| 温泉县| 夹江县| 门头沟区| 甘泉县| 鄂托克旗| 齐河县| 观塘区| 白河县| 南雄市| 垣曲县| 勐海县| 盐津县| 浏阳市| 偏关县| 淮滨县| 浙江省| 卓尼县| 灵台县| 遵义县| 呼图壁县| 洛扎县| 额尔古纳市| 宜城市| 淮滨县| 长宁区| 朝阳区| 黎川县| 双鸭山市| 嵊泗县| 辛集市| 招远市| 淅川县| 静安区| 乌兰浩特市| 翁源县| 五华县| 南平市|