Android 如何在菜单项后的导航抽屉中创建文本视图?

Android 如何在菜单项后的导航抽屉中创建文本视图?,android,navigation-drawer,Android,Navigation Drawer,我需要有一个文本视图后,我的菜单项,它不应该是响应。我不需要通过编程来更新它。我正在使用导航抽屉活动。我可以用文本创建一个图像,这样图像视图的实现也会有所帮助。 我想您已经有了navigation_view.xml?我不知道您使用哪种代码和版本来创建导航菜单。但是我有三个建议给你。 如果您使用“android.support.design.widget.NavigationView”,其中一个代码如下: <android.support.design.widget.Navigation

我需要有一个文本视图后,我的菜单项,它不应该是响应。我不需要通过编程来更新它。我正在使用导航抽屉活动。我可以用文本创建一个图像,这样图像视图的实现也会有所帮助。



我想您已经有了navigation_view.xml?

我不知道您使用哪种代码和版本来创建导航菜单。但是我有三个建议给你。 如果您使用“android.support.design.widget.NavigationView”,其中一个代码如下:

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

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:menu="@menu/menu_drawer">

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

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="your Sentences" />
</LinearLayout>

最后一个建议是在菜单中使用不同的列表项。在适配器中使用
getViewTypeCount()
getItemViewType(int位置)
。请参见

我尝试使用线性布局、帧布局等,但它们没有可滚动的行为。使用组项并没有给文本视图带来我想要的灵活性。我从另一个答案中得到了这个答案

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/activity_nav_drawer__main_drawer">
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_drawer_bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:headerLayout="@layout/nav_footer"/>
</android.support.design.widget.NavigationView>


将另一个嵌套导航视图与底部对齐,并为其提供自己的标题,将使其与底部对齐,您可以在其中放置图像视图或文本视图。

您可以尝试这种方法。。我发布的详细信息代码可能会对您有所帮助

1)这是出现导航抽屉的主类

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!--<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    android:background="@color/app_blue"
    app:itemIconTint="@color/app_white"
    app:itemTextColor="@color/app_white">
</android.support.design.widget.NavigationView>-->
<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer"
    android:background="@color/app_blue"
    app:itemIconTint="@color/app_white"
    app:itemTextColor="@color/app_white">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="match_parent"
        android:scrollbars="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                app:elevation="0dp"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"

                app:headerLayout="@layout/nav_header_main"
                app:menu="@menu/activity_main_drawer"
                android:background="@color/app_blue"
                app:itemIconTint="@color/app_white"
                app:itemTextColor="@color/app_white">
                ></android.support.design.widget.NavigationView>

            <LinearLayout
                android:id="@+id/spacer_to_bottom"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <include layout="@layout/nav_footer_main"></include>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_menu_camera"
        android:title="@string/menu_home" />
    <item
        android:id="@+id/nav_reg_log"
        android:icon="@drawable/ic_menu_gallery"
        android:title="@string/menu_reg_log" />
    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/ic_menu_slideshow"
        android:title="@string/menu_profile" />
    <item
        android:id="@+id/nav_notification"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_notificatio" />
    <item
        android:id="@+id/nav_post_offer"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_post_offer" />
    <item
        android:id="@+id/nav_history"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_history" />
    <item
        android:id="@+id/nav_review"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_review" />
    <item
        android:id="@+id/nav_blog"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_blog" />
</group>


<!--<item android:title="Communicate">
    <menu>
        <item
            android:id="@+id/nav_share"
            android:icon="@drawable/ic_menu_share"
            android:title="Share" />
        <item
            android:id="@+id/nav_send"
            android:icon="@drawable/ic_menu_send"
            android:title="Send" />
    </menu>
</item>-->
</menu>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_blue"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="I am the footer" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="I'm always at the bottom of the sidemenu" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Muhaiminurabir@gmail.com" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Follow Us"
    android:textColor="@color/app_white"
    android:textSize="18sp"
    android:textStyle="bold" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5">
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>


在菜单xml中放入文本视图这有什么问题?@KhizarHayat我想你做不到。你能给我一个示例代码吗?我从你的问题中了解到,你想要在侧菜单(导航抽屉项目)中显示文本视图@KhizarHayat用图像编辑问题进入导航视图布局查找此行应用程序:headerLayout=“any layout”进入该布局并编辑你想要的任何内容
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_menu_camera"
        android:title="@string/menu_home" />
    <item
        android:id="@+id/nav_reg_log"
        android:icon="@drawable/ic_menu_gallery"
        android:title="@string/menu_reg_log" />
    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/ic_menu_slideshow"
        android:title="@string/menu_profile" />
    <item
        android:id="@+id/nav_notification"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_notificatio" />
    <item
        android:id="@+id/nav_post_offer"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_post_offer" />
    <item
        android:id="@+id/nav_history"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_history" />
    <item
        android:id="@+id/nav_review"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_review" />
    <item
        android:id="@+id/nav_blog"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_blog" />
</group>


<!--<item android:title="Communicate">
    <menu>
        <item
            android:id="@+id/nav_share"
            android:icon="@drawable/ic_menu_share"
            android:title="Share" />
        <item
            android:id="@+id/nav_send"
            android:icon="@drawable/ic_menu_send"
            android:title="Send" />
    </menu>
</item>-->
</menu>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_blue"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="I am the footer" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="I'm always at the bottom of the sidemenu" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Muhaiminurabir@gmail.com" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Follow Us"
    android:textColor="@color/app_white"
    android:textSize="18sp"
    android:textStyle="bold" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5">
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>