2

我试图在kitkat具有以下FrameLayout实现Translucent StatusBar,它的工作没有CoordinatorLayout这样的:半透明状态栏上的FrameLayout工具栏上面的奇巧和使用CoordinatorLayout

Layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="1"> 

    <FrameLayout 
     android:id="@+id/statusbar" 
     android:layout_width="match_parent" 
     android:layout_height="25dp" 
     android:background="@color/colorPrimaryDark" /> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:background="@color/colorPrimary" /> 

</LinearLayout> 

而这条线在Styles.xml-v19当然是:

<item name="android:windowTranslucentStatus">true</item> 

,当然还有在onCreate

if (Build.VERSION.SDK_INT < 19) { 

      FrameLayout statusbar = (FrameLayout) findViewById(R.id.statusbar); 
      statusbar.setVisibility(View.GONE); 
     } 

和起作用的:

enter image description here

但是,我不知道怎样才能实现与CoordinatorLayoutAppbarLayout

这是我尝试的方式:

<android.support.design.widget.AppBarLayout 
      android:id="@+id/app_bar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/toolbarCollapse" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       app:contentScrim="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

       <FrameLayout 
        android:id="@+id/statusbar" 
        android:layout_width="match_parent" 
        android:layout_height="25dp" 
        android:background="?attr/colorPrimaryDark" /> 

        <android.support.v7.widget.Toolbar 
         android:id="@+id/toolbarmain" 
         android:layout_width="match_parent" 
         android:layout_height="?attr/actionBarSize" 
         android:background="@color/ColorPrimary" 
         app:layout_scrollFlags="scroll|enterAlways" 
         app:popupTheme="@style/ToolbarStylepopuptheme" 
         app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 


      </android.support.design.widget.CollapsingToolbarLayout> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="?attr/colorPrimary" 
       android:minHeight="?attr/actionBarSize" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:tabIndicatorColor="@android:color/white" 
       app:tabIndicatorHeight="2dp" 
       app:tabMode="scrollable" /> 

     </android.support.design.widget.AppBarLayout> 

,并没有工作。

更新:另外这个人是不工作:

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    android:fitsSystemWindows="true" 
    tools:context=".ui.MainActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@+id/statusBar" 
      android:layout_width="match_parent" 
      android:layout_height="25dp" 
      android:background="@color/colorPrimaryDark" 
      android:translationZ="8dp" /> 

     <android.support.design.widget.CoordinatorLayout 
      android:id="@+id/root_coordinator" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v4.widget.NestedScrollView 
       android:id="@+id/nestedscrollview" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

... 
... 

任何解决方案来实现这一目标?

类似ADM app on GooglePlay设计。

另外,让我们来提一下,当我使用CoordinatorLayout(相同条件)时,我遇到了与SystemBarTint相同的问题。我想不出他们怎么能做到这一点。

此外,这里有一个很好的教程,https://youtu.be/YCThIedqbCQ,但它不适合我。

回答

1

你不能这样做吗?当你不需要时,你似乎将你的虚假状态栏移动到协调器布局中?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:weightSum="1"> 

<FrameLayout 
    android:id="@+id/statusbar" 
    android:layout_width="match_parent" 
    android:layout_height="25dp" 
    android:background="@color/colorPrimaryDark" /> 

<Coordinator> 
    <AppBarLayout> 
     <CollapsibleToolbarLayout> 
      <Toolbar/> 
     </CollapsibleToolbarLayout> 
    </AppBarLayout> 
    <NestedScrollView/> 
</Coordinator> 
</LinearLayout> 
+1

总结这里面'FrameLayout',所以状态栏'FrameLayout'沾到它下面的顶部和一切幻灯片。 –

+0

这完全忽略了适合系统Windows的点...但考虑它是多么的破碎,我不会责怪任何人使用这种解决方法。 –

+0

@ Su-AuHwang - 那么,你有什么建议? – Mohsen

相关问题