hra*_*ach 10 android material-design android-support-design
首先,我想提一下,有大量的问题和各种质量的答案,实际上我找不到一个好的解释,推理和解决问题的方法.
我想要:
windowTranslucentStatus=true DrawerLayout)colorPrimaryDark代替我画画.(可能android:fitsSystemWindows="true")从各种资源中我已经意识到根布局之间存在差异,所以我所有的试验都是完全CoordinatorLayout适合的,并且已经为此做好了准备.(直接来自支持库,包含在所有样本中,包括工具栏,应用栏布局等)
我目前的设置:
编译api 27,支持libs版本27*
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<fragment
android:id="@+id/fragment"
android:name="com.sygic.travel.materialtest5.MainActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
价值观/ styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>
Run Code Online (Sandbox Code Playgroud)
值-V21/styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
结果如下:
问题:
windowTranslucentStatus并且fitsSystemWindows没有"白/灰"状态栏吗?fitsSystemWindows,但(内部)属性(用于处理此属性)保持为null,如何解决这个问题?或者仅用于手动设置状态栏的颜色?android:statusBarColor考虑风格选项?哪个组件使用此值?为什么CoordinationLayout不选择此配置(使用其默认的primaryColorDark)并使用它?笔记:
好的,我试着检查代码,发现这是解决方案!:好极了:
首先,我的问题的一些答案:
DrawerLayout这是自动的,CoordinatorLayout也可以,见下.app:statusBarBackground可以直接在样式中的xml标签上设置!所以解决方案是使用CoordinatorLayout和statusBarBackground属性:
values-v21/styles.xml
<resources>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="statusBarBackground">@color/colorPrimary</item>
</resources>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
535 次 |
| 最近记录: |