设置使用AppCompat-V-21工具栏小工具NavigationDrawer图标右侧 [英] Set NavigationDrawer icon right side using AppCompat-V-21 Toolbar Widget

查看:218
本文介绍了设置使用AppCompat-V-21工具栏小工具NavigationDrawer图标右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在材料设计采用了最新的工具栏控件在AppCompact-V21提供与导航抽屉工作。

我关心的是如何设置抽屉式导航图标,在右侧工具栏中的的。 虽然我可以从右边打开抽屉式导航通过设置机器人:layout_gravity =正确的,但导航图标仍然显示是在左侧的工具栏

使用旧当操作栏,我可以用按钮右侧的定制抽屉图标上的自定义导航抽屉图标点击打开箱子的自定义操作栏/关上抽屉

  1. 什么是方法,使用工具栏上的右侧设置抽屉式导航图标?
  2. 如何为它创建自定义视图?
解决方案

那么,自定义工具栏和设置您自己的导航按钮,你可以添加自己的ImageButton到工具栏:

 < android.support.v7.widget.Toolbar
       的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       机器人:ID =@ + ID /工具栏
       机器人:=了minHeight?ATTR / actionBarSize
       机器人:layout_height =?ATTR / actionBarSize
       机器人:layout_width =match_parent>

       <的ImageButton
           机器人:layout_width =WRAP_CONTENT
           机器人:layout_height =WRAP_CONTENT
           机器人:layout_gravity =结束
           机器人:的onClick =backButtonHandler
           机器人:背景=@可绘制/ ic_launcher/>

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

然后,您可以在活动类定义backButtonHandler(视图V),并根据需要添加功能。

I've been working in material design using the latest Toolbar Widget provided in AppCompact-V21, with the navigation drawer.

My concern is How can I set navigation drawer icon to right side of the toolbar. Although I can open navigation drawer from right by setting the android:layout_gravity="right" but navigation icon still appears to be on left side in toolbar.

When Using old Action Bar, I can crate custom action bar with button to right side with custom drawer icon and on click of custom navigation drawer icon open/close the drawer.

  1. What is way to set navigation drawer icon on right side using toolbar ?
  2. How to create custom view for it ?

解决方案

Well, to customize toolbar and setting your own navigation button, you can add your own imagebutton to the toolbar :

<android.support.v7.widget.Toolbar
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/toolbar"
       android:minHeight="?attr/actionBarSize"
       android:layout_height="?attr/actionBarSize"
       android:layout_width="match_parent">

       <ImageButton
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="end"
           android:onClick="backButtonHandler"
           android:background="@drawable/ic_launcher"/>

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

Then, you can define your backButtonHandler(View v) in your activity class, and add functionality as desired.

这篇关于设置使用AppCompat-V-21工具栏小工具NavigationDrawer图标右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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