使用Android上的设计支持库切换导航抽屉项 [英] Switch in Navigation drawer item with Design Support Library on Android

本文介绍了使用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.

这篇关于使用Android上的设计支持库切换导航抽屉项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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