Android中API级别19中未显示工具栏
我阅读并尝试重新排列视图,但在Android 19上仍然看不到工具栏 我不知道为什么android 19上的工具栏不可见 这是最新的Android中API级别19中未显示工具栏,android,android-toolbar,Android,Android Toolbar,我阅读并尝试重新排列视图,但在Android 19上仍然看不到工具栏 我不知道为什么android 19上的工具栏不可见 这是最新的 试试下面的布局 <RelativeLayout android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/a
试试下面的布局
<RelativeLayout
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
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="50dp"
android:background="@color/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageButton
android:id="@+id/bt_picture"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_photo_white_24dp" />
<ImageButton
android:id="@+id/bt_pdf"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_picture_as_pdf_white_24dp" />
<ImageButton
android:id="@+id/bt_clear"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_delete_white_36dp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<com.example.ricardochampa.signatureapp.SignatureView
android:id="@+id/signature_view"
android:layout_below="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="@+id/line_view"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:layout_marginStart="70dp"
android:background="@color/grey"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/line_view"
android:layout_centerHorizontal="true"
android:textColor="@color/grey"
android:layout_marginTop="10dp"
android:text="@string/sign_here" />
</RelativeLayout>
原因是
工具栏
正在通过SignatureView
隐藏。虽然我现在不知道它是如何在19岁以上变得可见的 您的SignatureView
具有layout\u height=match\u parent
且不受约束。因此,它将覆盖整个屏幕,包括工具栏。但为什么这只发生在API上?请看一下答案中@Ben P的评论。它说得很清楚。标高是一个仅在21+APIsOn Lollipop+上可用的属性,标高比视图在布局中声明的顺序更重要。由于工具栏有4dp标高,而其他任何东西都没有,所以在Lollipop+上,您将能够看到它,即使它是在布局中首先声明的。我从未测试过这种情况,也没有在材质设计文档中的任何地方读到过它。谢谢分享。你能指出同样的文件吗?我不能。这并不是说它没有记录,但如果有,我不知道在哪里。我只是有自己的个人经验可以借鉴。尽管需要注意的是,如果您将视图视为在Z轴上的其他视图上方浮动,那么这在逻辑上是有意义的。
<RelativeLayout
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
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="50dp"
android:background="@color/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageButton
android:id="@+id/bt_picture"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_photo_white_24dp" />
<ImageButton
android:id="@+id/bt_pdf"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_picture_as_pdf_white_24dp" />
<ImageButton
android:id="@+id/bt_clear"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginEnd="10dp"
android:background="@drawable/ic_delete_white_36dp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<com.example.ricardochampa.signatureapp.SignatureView
android:id="@+id/signature_view"
android:layout_below="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="@+id/line_view"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:layout_marginStart="70dp"
android:background="@color/grey"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/line_view"
android:layout_centerHorizontal="true"
android:textColor="@color/grey"
android:layout_marginTop="10dp"
android:text="@string/sign_here" />
</RelativeLayout>
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if(getSupportActionBar()!=null){
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}