android - 如何从左到右工具栏api 16
问题描述
我正在使用NavigationView并使用include添加工具栏。我使用并且所有 api 都可以正常工作,但在api 16中它不起作用。android:layoutDirection="rtl"
那么我如何在 api 16 中从左到右工具栏?
抽屉布局.xml
<?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"
android:layoutDirection="rtl"
tools:openDrawer="end">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/appbar" />
<include
android:id="@+id/appbar"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layoutDirection="rtl"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_main.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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
MainActivity.java
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
解决方案
推荐阅读
- python - 我应该在 keras 中使用什么损失函数和度量来进行多标签分类?
- java - 无法在 Android Studio 中读取 JSON
- c++ - ESP32 尝试重新连接到网络断开时没有停止循环(Arduino)
- python - 使用 AES-GCM 加密不适合 RAM 的大文件
- python - 堆叠布局导致对齐顶部问题
- google-bigquery - bigquery 预订是自动的吗?
- c# - 如何在静态类中绑定属性?
- reactjs - 我的反应钩子在我的反应组件中使用时失败,该组件深深嵌入到我的反应应用程序中
- node.js - 程序在继续流程之前不等待异步功能
- java - 不可变 @Value.Immutable 公共最终字段(而不是 getter)