84669 人學習
152542 人學習
20005 人學習
5487 人學習
7821 人學習
359900 人學習
3350 人學習
180660 人學習
48569 人學習
18603 人學習
40936 人學習
1549 人學習
1183 人學習
32909 人學習
我想在5.0 或者4.4 操作系统都实现沉淀式状态栏或透明状态栏,最好全部都采用style 的方式实现,最好不用这个开源库https://github.com/jgilfelt/SystemBarTint求解决思路
经过这几天的思考和研究,发现使用ActionBar,和不使用ActionBar,改为Toolbar 效果完全是不一样的,那在这两种情况下是否都可以完美的实现呢
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
對於top view, 可以用style,
<style name="TopViewStyle"> <item name="android:fitsSystemWindows">true</item> <item name="android:clipToPadding">true</item> </style>
但window flag還是需要程式碼做版本支援判斷的,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
是沒法在style中表示的,style自己做不了版本標識區別。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/top_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/TopViewStyle"/> <TextView android:id="@+id/example_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } }
自己的解決方案:https://coding.net/u/tianshaokai/p/MaterialDesignDemo/git低版實現Material Design 的兩種方式https://github.com/Witype/ SystemBarTintDemohttps://github.com/Witype/ToolbarStatusDemo
實現狀態列沉浸非常簡單,而且只需要透過style配置在 values-v19 下的 styles.xml 裡定義如下主題,並在 Manifest.xml 裡將應用主題確定為這個主題即可。
values-v19
styles.xml
Manifest.xml
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">false</item> </style>
android:windowTranslucentStatus 表示狀態列透明android:windowTranslucentNavigation 表示導覽列(虛擬按鍵列)透明
android:windowTranslucentStatus
android:windowTranslucentNavigation
沉浸是小事,關鍵麻煩在對 layout 佈局裡的改動,fitsSystemWindows 的優化,憑經驗告訴你,SystemBarTint已經算是最簡單的解決方案。
layout
fitsSystemWindows
對於top view, 可以用style,
但window flag還是需要程式碼做版本支援判斷的,
是沒法在style中表示的,style自己做不了版本標識區別。
activity_main.xml
MainActivity.java
自己的解決方案:https://coding.net/u/tianshaokai/p/MaterialDesignDemo/git
低版實現Material Design 的兩種方式
https://github.com/Witype/ SystemBarTintDemo
https://github.com/Witype/ToolbarStatusDemo
實現狀態列沉浸非常簡單,而且只需要透過style配置
在
values-v19
下的styles.xml
裡定義如下主題,並在Manifest.xml
裡將應用主題確定為這個主題即可。android:windowTranslucentStatus
表示狀態列透明android:windowTranslucentNavigation
表示導覽列(虛擬按鍵列)透明沉浸是小事,關鍵麻煩在對
layout
佈局裡的改動,fitsSystemWindows
的優化,憑經驗告訴你,SystemBarTint已經算是最簡單的解決方案。