我试图设置在工具栏上的导航图标复选框像棒棒堂画廊:如何在Android工具栏导航图标中设置复选框?
我知道你可以用图像绘制这样的改变:
mToolbar.setNavigationIcon(iconRes);
但我如何将导航图标更改为复选框?我试图用一个自定义布局,但没有工作:
checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />
</RelativeLayout>
,并在活动:
mToolbar.setNavigationIcon(R.layout.checkbox);
但是,这是行不通的。
您可以将复选框作为子布局放入xml中的工具栏布局中。 – Sharj
如果我把复选框作为工具栏布局中的一个子项,复选框位于标题的右侧。我希望复选框位于标题的左侧。 –
您不必使用默认标题'TextView'。您可以在复选框右侧添加自己的TextView来设置标题。 – Sharj