<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                **(一):寫在前面的話**? ? ? ? ?【好消息】個人網站已經上線運行,后面博客以及技術干貨等精彩文章會同步更新,請大家關注收藏:[http://www.lcode.org](http://www.lcode.org/)? ? ? ? ?接著上一篇繼續更新,上一篇文章已經把FastDev4Android項目崩潰異常捕捉組件(CustomCrash)做了講解和使用。今天項目更新沉浸式狀態欄功能的實現和使用。因為名字叫【Translucent Bars】至于取名的討論問題大家有興趣可以看一下知乎上面的討論([傳送門](http://www.zhihu.com/question/27040217 "傳送門"))? ? ? ? ?Google從android kitkat(Android 4.4)開始,給我們開發者提供了一套能透明的系統ui樣式給狀態欄和導航欄,這樣的話就不用向以前那樣每天面對著黑乎乎的上下兩條黑欄了,還可以調成跟Activity一樣的樣式,形成一個完整的主題,和IOS7.0以上系統一樣哈。下面我們來看下國內應用的效果:? ![](https://box.kancloud.cn/2016-01-18_569c8eb16f100.jpg)? **(二):沉浸式狀態欄功能實現:**? 2.1:系統方式? 2.1.1:設置狀態欄和導航? 我們在Activity onCreate()方法中進行如下設置,因為該功能是Android4.4開始才提供,所以我們需要判斷以下系統版本: ~~~ //當系統版本為4.4或者4.4以上時可以使用沉浸式狀態欄 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //透明狀態欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明導航欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } ~~~ 或者可以如下設置: ~~~ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); } @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); } ~~~ 這樣設置完之后看運行效果如下:? ![](https://box.kancloud.cn/2016-01-18_569c8eb18b7a5.jpg)? 如上應用整體往上移動了狀態欄的高度,所以我們需要進行獲取狀態欄的高度并且布局中加入一個占位的小布局來搞定? 2.1.2:獲取狀態欄的高度 ~~~ /** * 獲取狀態欄的高度 * @return */ private int getStatusBarHeight(){ try { Class<?> c=Class.forName("com.android.internal.R$dimen"); Object obj=c.newInstance(); Field field=c.getField("status_bar_height"); int x=Integer.parseInt(field.get(obj).toString()); return getResources().getDimensionPixelSize(x); }catch(Exception e){ e.printStackTrace(); } return 0; } ~~~ 2.1.3:設置占位控件的高度? 這樣原有得布局不會發生改變。 ~~~ <LinearLayout android:id="@+id/linear_bar" android:layout_width="fill_parent" android:layout_height="1dp" android:orientation="vertical" android:background="#e7abff" android:visibility="gone" > </LinearLayout> ~~~ ~~~ LinearLayout linear_bar=(LinearLayout)findViewById(R.id.linear_bar); linear_bar.setVisibility(View.VISIBLE); int statusHeight=getStatusBarHeight(); android.widget.LinearLayout.LayoutParams params=(android.widget.LinearLayout.LayoutParams )linear_bar.getLayoutParams(); params.height=statusHeight; linear_bar.setLayoutParams(params); ~~~ 2.1.4:運行結果? ①:模擬器效果? ![](https://box.kancloud.cn/2016-01-18_569c8eb19b4cb.jpg)? ? ? ? ? ? ①:真機效果? ![](https://box.kancloud.cn/2016-01-18_569c8eb1afab8.jpg) 2.2:第三方控件(systembartint)實現庫地址([Github地址](https://github.com/jgilfelt/SystemBarTint))? 2.2.1:添加依賴庫 ~~~ compile 'com.readystatesoftware.systembartint:systembartint:1.0.3' ~~~ 2.2.2:設置狀態欄和導航和2.1.1方法一樣? 2.2.3:激活主題并且設置顏色 ~~~ SystemBarTintManager tintManager = new SystemBarTintManager(this); // 激活狀態欄 tintManager.setStatusBarTintEnabled(true); // enable navigation bar tint 激活導航欄 tintManager.setNavigationBarTintEnabled(true); //設置系統欄設置顏色 //tintManager.setTintColor(R.color.red); //給狀態欄設置顏色 tintManager.setStatusBarTintResource(R.color.middle_red); // 設置導航欄設置資源 tintManager.setNavigationBarTintResource(R.color.color_nav); ~~~ 2.2.4:布局修改適配和padding? 在當前Activity布局文件根節點上面作如下修改:? ![](https://box.kancloud.cn/2016-01-18_569c8eb1c6a8f.jpg)? 2.2.5:運行結果如下:? ①:模擬器效果? ![](https://box.kancloud.cn/2016-01-18_569c8eb204271.jpg)? ②:真機效果? ![](https://box.kancloud.cn/2016-01-18_569c8eb219069.jpg) 到此為止完成沉浸式狀態欄的實現和使用結果,如果大家有興趣去第三方控件(systembartint)實現庫地址([Github地址](https://github.com/jgilfelt/SystemBarTint))對這個庫做詳細了解。同時本項目代碼地址:? [https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)? 同時歡迎大家star和fork整個開源快速開發框架項目~如果有什么意見和反饋,歡迎留言,必定第一時間回復。也歡迎有同樣興趣的童鞋加入到該項目中來,一起維護該項目。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看