国产探花免费观看_亚洲丰满少妇自慰呻吟_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的手機上修改狀態欄顏色效果不是太好(可以在主題中直接修改狀態欄顏色)。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卓资县| 汪清县| 丹江口市| 凉城县| 佛山市| 丰原市| 炉霍县| 清河县| 古交市| 新泰市| 肇源县| 高要市| 台前县| 蓝山县| 东海县| 罗山县| 新建县| 大洼县| 秦安县| 惠水县| 浏阳市| 临夏县| 高尔夫| 临武县| 梁平县| 屯门区| 莆田市| 开江县| 河西区| 德惠市| 偏关县| 吉林市| 繁峙县| 山丹县| 临沧市| 博湖县| 钟山县| 留坝县| 鹿泉市| 嘉祥县| 镶黄旗|