自定义TextView看起来像菜单项

时间:2018-02-17 10:50:49

标签: android material-design menuitem

我正在尝试指定自己的Android导航抽屉。 显示了动态数据,因此我无法在menu.xml中进行设置。 现在我正在尝试将TextView的外观自定义到我的ListView中,看起来非常像菜单项,但这些类都是抽象的。此外,我无法在material.io找到有用的东西。

我在寻找:

enter image description here

我现在得到了什么:

enter image description here

以下是相应的XML:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".SlideshowActivity"
    android:id="@+id/drawer_slide_show">

    <android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="0dp"
        tools:context=".SlideshowActivity">


        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButtonRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:layout_marginRight="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_arrow_right"
            android:alpha="0.5"  />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButtonLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:layout_marginLeft="8dp"
            android:alpha="0.5"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_arrow_left" />


        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager_slideshow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent">

        </android.support.v4.view.ViewPager>

    </android.support.constraint.ConstraintLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">


        <ListView
            android:id="@+id/listView_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:dividerHeight="5px"
            android:listSelector="@drawable/ic_media_pause_dark" >

        </ListView>


    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

1 个答案:

答案 0 :(得分:0)

您需要使用自定义Adapter的listview自定义导航抽屉。这是自定义navigation drawer的示例。