适合fitSystemWindows的正确视图

时间:2017-05-24 11:37:22

标签: android xml statusbar transparent navigationbar

我想让导航栏完全透明,状态栏是透明的还是半透明的!

所以我在v21/styles

中添加了这些行
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>

这是onCreate

内的内容
   getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

并在根布局中

android:fitsSystemWindows="true"

导航栏显示透明,但状态栏重叠..!我试图在xml的每个布局中移动最后一行,但没有运气..有时它会停止重叠,但导航栏不再保持透明..!有什么帮助吗?

enter image description here enter image description here

完整的XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:autofit="http://schemas.android.com/apk/res-auto"
  xmlns:custom="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#2d2b30">


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


<android.support.v7.widget.Toolbar
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@color/colorToolbar"
  app:titleTextColor="@color/white"/>


<FrameLayout

  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <ImageView
    android:id="@+id/decoratoin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:alpha="0.017"
    android:elevation="5dp"
    android:scaleType="center"
    android:src="@drawable/decoration0"/>


  <!-- The Linearlayout with id="rootView"  is the one that contains the major views  -->

  <LinearLayout
    android:id="@+id/rootView"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView

      android:id="@+id/card"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="10dp"
      android:padding="5dp"
      app:cardBackgroundColor="#da2e2c30"
      app:cardCornerRadius="2dp"
      app:cardElevation="5dp">

      <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <me.grantland.widget.AutofitTextView
          android:id="@+id/txt"
          android:layout_width="match_parent"
          android:layout_height="95dp"
          android:layout_margin="2dp"
          android:padding="5dp"
          android:maxLines="4"
          android:text="ooooooooooo"
          android:textColor="#ffff"
          android:textSize="20sp"
          autofit:minTextSize="12sp"/>

        <ImageView
          android:id="@+id/swipe_arrow"
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_gravity="center_vertical|end"
          android:alpha="0.1"
          android:src="@drawable/swipe_icon"/>

      </FrameLayout>

    </android.support.v7.widget.CardView>

    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="15dp"
      android:layout_marginEnd="15dp"
      android:layout_gravity="center"
      android:orientation="horizontal">

      <ImageView
        android:id="@+id/reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp"
        android:layout_gravity="center_horizontal|center_vertical"
        android:padding="2dp"
        android:clickable="true"
        android:hapticFeedbackEnabled="true"
        android:src="@mipmap/reset"/>

      <TextView
        android:id="@+id/btn_edit"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp"
        android:layout_gravity="center_horizontal|center_vertical"
        android:padding="2dp"
        android:background="@mipmap/nums_max"
        android:clickable="true"
        android:elevation="10dp"
        android:hapticFeedbackEnabled="true"/>

      <TextView
        android:id="@+id/btn_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp"
        android:layout_gravity="center_horizontal|center_vertical"
        android:padding="1dp"
        android:background="@mipmap/azkar_list"
        android:clickable="true"
        android:elevation="10dp"
        android:hapticFeedbackEnabled="true"/>

    </LinearLayout>

    <FrameLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">


      <com.github.lzyzsd.circleprogress.ArcProgress
        android:id="@+id/arc_progress"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_marginTop="30dp"
        android:layout_marginStart="20dp"
        android:layout_marginEnd="20dp"
        android:layout_marginLeft="50dp"
        android:layout_gravity="center_horizontal"
        android:background="#2d2b30"
        custom:arc_bottom_text=" "
        custom:arc_bottom_text_size="35dp"
        custom:arc_finished_color="@color/colorAccent"
        custom:arc_progress="55"
        custom:arc_stroke_width="20dp"
        custom:arc_suffix_text=" "
        custom:arc_text_color="#84e43b"
        custom:arc_text_size="45dp"
        custom:arc_unfinished_color="#2cf2f2f1"/>

      <TextView
        android:id="@+id/check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:background="@drawable/check"
        android:visibility="gone"/>


    </FrameLayout>

  </LinearLayout>

 </FrameLayout>


</LinearLayout>

2 个答案:

答案 0 :(得分:0)

您是否尝试使用android:layout_below和layout_above?

答案 1 :(得分:0)

感谢 @azizbekian ,我从我的xml中删除了android:fitsSystemWindows="true",然后将此监听器添加到我的工具栏中..!它起作用了:D

  toolbar.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
  @Override
  public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
    ((MarginLayoutParams) v.getLayoutParams()).topMargin =
        insets.getSystemWindowInsetTop();
    return insets.consumeSystemWindowInsets();
  }
});

有关此问题的更多详细信息,请参阅他的medium article.