Home  >  Q&A  >  body text

How does Android implement menu and immersive status bar to coexist?

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中文网2702 days ago620

reply all(3)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-27 17:42:01

    Add a button to the layout, simple and crude.

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-27 17:42:01

    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)

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-27 17:42:01

    One line of code to get it done

    reply
    0
  • Cancelreply