使用Android上的设计支持库切换导航抽屉项
问题描述:
我需要将Switch放在导航抽屉中.我正在使用新的设计支持库,但根本找不到它.使用
I need to put Switch inside item in navigation drawer. I'm using new design support library, but I cannot find if it is posibble at all. When using
android:checkable
项目完全被选中,这不是我想要的.
item is just full selected and that is not what I wish.
这是我真正想要的屏幕截图.有可能实现这一目标吗?
This is screenshot of what I really want. Is that possible to achieve that?
答
导航抽屉的菜单项:
<item
android:id="@+id/nav_item1"
android:icon="@drawable/ic_item1"
android:title="item1"
app:actionLayout="@layout/layout_switch"
/>
以及该项目的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SwitchCompat
android:id="@+id/drawer_switch"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text=""/>
</LinearLayout>
我最终使用了另一种方法.实际上,我发现您可以在抽屉中使用任何视图,因此不必理会菜单内容.只需使用通常的方式(使用侦听器等)创建视图,然后添加到抽屉中即可.
I ended up using a different approach. In fact, I found out that you can use any view in the drawer, so there's no point in bothering with the menu stuff. Just create a view the usual way (with listeners, etc.) and add in to the drawer.