How does Android implement menu and immersive status bar to coexist?
PHP中文网
PHP中文网 2017-05-27 17:40:01
0
3
649

This is the effect of Xiaomi weather


I tried this, but the menu is not displayed in the immersive status bar. Similar to this, how to add a menu and display it while keeping NoActionBar?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
我想大声告诉你

Add a button to the layout, simple and crude.

大家讲道理

0. Reference the Support package

1. Define Theme

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowContentOverlay">@null</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowActionBar">?attr/windowActionBar</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowNoTitle">?attr/windowNoTitle</item>
    
    <!-- 状态栏颜色 -->
    <item name="colorPrimaryDark">#??????</item>
    <!--<item name="android:statusBarColor">@android:color/transparent</item>-->
    <!--<item name="android:windowTranslucentStatus">true</item>-->
    <item name="android:windowTranslucentNavigation">true</item>
</style>

2. Define Layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        xmlns:appCompat="http://schemas.android.com/apk/res-auto"
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="?actionBarTheme">
        
        <android.support.v7.widget.Toolbar 
            android:id="@+id/ab_toolbar"
            style="?attr/actionBarStyle"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            appCompat:contentInsetEnd="@dimen/margin"
            appCompat:contentInsetStart="0dp"
            appCompat:contentInsetStartWithNavigation="0dp"
            appCompat:layout_collapseMode="none"
            appCompat:popupTheme="?attr/actionBarPopupTheme">
           
           <!-- YOUR LAYOUT -->

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
        
    <!-- YOUR LAYOUT -->
    
</FrameLayout>

3. Implement Activity

  • Quoting the above Theme & Layout

  • Call void setSupportActionBar (Toolbar toolbar)

  • Define MenuLayout

  • Rewriteboolean onCreateOptionsMenu (Menu menu) & boolean onPrepareOptionsMenu (Menu menu) & boolean onOptionsItemSelected (MenuItem item)

大家讲道理

One line of code to get it done

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!