在工具栏底部边缘显示的工具栏向上箭头图标
问题描述:
我在我的应用程序中使用了以下依赖项。但工具栏向上箭头图标显示在工具栏底部边缘。是否在我的代码中存在任何问题?在工具栏底部边缘显示的工具栏向上箭头图标
compileSdkVersion 23
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.company.appname"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
dependencies {
compile('com.android.support:cardview-v7:23.2.0') {
force = true
}
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:gridlayout-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
GalleryActivity.java
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
TextView toolBarTitleTextView = (TextView) findViewById(R.id.gallery_activity_toolbar_title);
toolBarTitleTextView.setText(R.string.title_gallery_fragment);
activity_gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.company.appname.activities.GalleryActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/AppTheme.ToolbarOverlay"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/gallery_activity_toolbar_title"
style="@style/App.Widget.TextView.Toolbar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<fragment
android:id="@+id/gallery_fragment"
android:name="com.company.appname.fragments.GalleryFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_gallery" />
</android.support.design.widget.CoordinatorLayout>
答
尝试增加android:fitsSystemWindows="true"
到AppBarLayout
答
背后的主要原因是android:fitsSystemWindows="true"
奇怪它为什么不工作。
您可以尝试此备用解决方案。 给你的风格这个属性。
<item name="android:fitsSystemWindows">true</item>
答
从CoordinatorLayout中删除了android:fitsSystemWindows =“true”。它很棒!