4.4適合浸透式詳細
11318 ワード
4.4適合浸透式
values/colors.xml
values/styles.xml
values-v19/styles.xml
values-v21/styles.xml
レイアウトファイル
layout/app_bar_main.xml
layout/activity_main.xml
*注意点: NavigationView android:fitsSystemWindows="true" は設定されていません CoordinatorLayout設定android:fitsSystemWindows="true" values-v 21でTheme属性androidを設定:statusBarColor透明 Activityコード
SystemBarTintManager(https://github.com/jgilfelt/SystemBarTint)、ステータスバーの色を設定
注:5.0以上のAndroidバージョンは自動的に適合します.themeトピックのプロパティは、追加の適合は必要ありません.
現在のAndroidバージョンが4.4に等しい場合は、SystemBarTintManagerを使用します.
values/colors.xml
<resources>
<color name="colorPrimary">#3F51B5color>
<color name="colorPrimaryDark">#303F9Fcolor>
<color name="colorAccent">#FF4081color>
resources>
values/styles.xml
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary
- "colorPrimaryDark"
>@color/colorPrimaryDark
- "colorAccent">@color/colorAccent
style>
<style name="AppTheme" parent="@style/BaseTheme">
style>
values-v19/styles.xml
<resources>
<style name="AppTheme" parent="@style/BaseTheme">
<item name="android:windowTranslucentStatus">trueitem>
style>
resources>
values-v21/styles.xml
レイアウトファイル
layout/app_bar_main.xml
"1.0" encoding="utf-8"?>
.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="com.example.fullstack.MainActivity">
.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
.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" />
.support.design.widget.AppBarLayout>
"@layout/content_main" />
.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
.support.design.widget.CoordinatorLayout>
layout/activity_main.xml
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
android.support.v4.widget.DrawerLayout>
*注意点:
SystemBarTintManager(https://github.com/jgilfelt/SystemBarTint)、ステータスバーの色を設定
注:5.0以上のAndroidバージョンは自動的に適合します.themeトピックのプロパティは、追加の適合は必要ありません.
if(Build.VERSION.SDK_INT==Build.VERSION_CODES.KITKAT){
SystemBarTintManager systemBarTintManager=new SystemBarTintManager(this);
systemBarTintManager.setStatusBarTintEnabled(true);
systemBarTintManager.setStatusBarTintResource(statusBarColor);
systemBarTintManager.setNavigationBarAlpha(0.2f);
}
現在のAndroidバージョンが4.4に等しい場合は、SystemBarTintManagerを使用します.