如何在项目文本的右侧设置导航抽屉图标? [英] How to set Navigation Drawer icons to the right side of the Item Texts?

查看:131
本文介绍了如何在项目文本的右侧设置导航抽屉图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目屏幕截图:我的项目

我的目标设计:我的目标

我已经创建了一个(从右到左)导航抽屉.它工作正常,但是当我尝试将图标从左侧移动到右侧时,它不起作用.

I have created a (right to left) navigation drawer. It's working fine but when I'm trying to move the icon from the left side to the right side, it's not working.

<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:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:background="@color/nav"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemIconTint="#d2a967"
    app:itemTextColor="#d2a967"
    app:menu="@menu/activity_main_drawer" />

注意:我的API是14 +

Attention: My API is 14+

推荐答案

如果目标API为17+,则使用此选项打开导航抽屉的右侧.

use this open your Navigation drawer right side if your target API is 17+

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
  }

尝试此操作,如下所示创建新的布局

Try this Create a new Layout like below

 <TextView
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/tv_badge"
       android:layout_width="wrap_content"
       android:drawableRight="@mipmap/ic_launcher_round"
       android:layout_height="wrap_content" />

使用以下代码将自定义"视图设置为导航"视图

than set Custom view to Your navigation view using below code

 YourNavigationView.getMenu().getItem(0).setActionView(R.layout.custom_layout);

setActionView(int resId)

setActionView(int resId)

为此菜单项设置操作视图.

Set an action view for this menu item.

编辑

尝试此操作修改您的单个导航菜单项

try this to modify your single navigation menu item

TextView  textView = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
textView.setText("ONE");
textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_favourite, 0, 0);
textView.setTextColor(ContextCompat.getColor(this,R.color.colorPrimary));
navigationView.getMenu().getItem(0).setActionView(textView);

这篇关于如何在项目文本的右侧设置导航抽屉图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆