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

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

SystemBarTint實現沉浸模式

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

先看幾張圖對比一下在不同版本的顯示效果 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的手機上修改狀態欄顏色效果不是太好(可以在主題中直接修改狀態欄顏色)。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盐边县| 新源县| 连云港市| 永寿县| 榆社县| 泌阳县| 克东县| 武隆县| 台南市| 石楼县| 黑龙江省| 增城市| 白山市| 锡林浩特市| 永仁县| 弥勒县| 泰和县| 东乌珠穆沁旗| 杭州市| 海口市| 海兴县| 衡南县| 大港区| 平阴县| 个旧市| 应用必备| 宜宾县| 台北市| 大埔区| 饶平县| 广河县| 容城县| 商南县| 宜阳县| 海盐县| 海林市| 临沂市| 龙门县| 澄迈县| 安福县| 南宫市|