如何更改抽屉标题?

时间:2018-11-05 08:46:56

标签: java android android-layout

我是Android新手,正在开发App。我正在尝试开发具有抽屉式布局的应用程序。一切都很好,但是我无法更改屏幕快照上标记的抽屉菜单的标题。

Image 1: App Home

为方便起见,这里是布局文件。我已从此link获得帮助:

<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<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">

    <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/user_home_main_view">

        <Button
            android:id="@+id/button_mutual_funds_icl"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="252dp"
            android:layout_height="49dp"
            android:layout_marginTop="120dp"
            android:layout_marginEnd="16dp"
            android:text="Mutual Funds of ICL"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/icon_mutual_funds_of_icl"
            android:layout_width="51dp"
            android:layout_height="49dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="120dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toStartOf="@+id/button_mutual_funds_icl"
            app:layout_constraintHorizontal_bias="0.384"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/mutual_funds_of_icl" />

        <Button
            android:id="@+id/button_current_nav"
            android:layout_width="252dp"
            android:layout_height="49dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="16dp"
            android:text="Current NAVs"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_mutual_funds_icl" />

        <ImageView
            android:id="@+id/icon_current_nav"
            android:layout_width="51dp"
            android:layout_height="49dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toStartOf="@+id/button_current_nav"
            app:layout_constraintHorizontal_bias="0.458"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/icon_mutual_funds_of_icl"
            app:srcCompat="@drawable/net_asset_value" />

        <Button
            android:id="@+id/button_fund_performance"
            android:layout_width="250dp"
            android:layout_height="49dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="16dp"
            android:text="Fund Performance"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_current_nav" />

        <ImageView
            android:id="@+id/icon_fund_performance"
            android:layout_width="51dp"
            android:layout_height="49dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="26dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toStartOf="@+id/button_fund_performance"
            app:layout_constraintHorizontal_bias="0.448"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/icon_current_nav"
            app:srcCompat="@drawable/fund_performance" />

        <Button
            android:id="@+id/button_how_to_invest"
            android:layout_width="249dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="28dp"
            android:layout_marginEnd="16dp"
            android:text="How to Invest"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_fund_performance" />

        <ImageView
            android:id="@+id/icon_how_to_invest"
            android:layout_width="53dp"
            android:layout_height="49dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="36dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toStartOf="@+id/button_how_to_invest"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/icon_fund_performance"
            app:srcCompat="@drawable/how_to_invest" />

        <Button
            android:id="@+id/user_home_button_invest_now"
            android:layout_width="214dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="141dp"
            android:layout_marginEnd="8dp"
            android:background="@color/colorPrimary"
            android:text="Invest Now"
            android:textColor="@color/colorAccent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.513"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_how_to_invest" />

    </android.support.constraint.ConstraintLayout>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

    </FrameLayout>

    <!-- Container for contents of drawer - use NavigationView to make configuration easier -->
    <android.support.design.widget.NavigationView
        android:id="@+id/user_nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_view"
        app:headerLayout="@layout/nav_header"/>


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

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

更多自定义

如果要对抽屉进行更多自定义。您可以为抽屉创建布局,并将其包含在0x48b660
中 像这样

android.support.design.widget.NavigationView

然后您可以为</android.support.v4.widget.DrawerLayout> ........... <!- Drawer > <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="150dp" android:layout_height="match_parent" android:fitsSystemWindows="true" android:layout_gravity="left" > <!--- Your custom layout > <include layout="@layout/custom_drawer_layout" android:id="@+id/filterDrawer" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="end" /> </android.support.design.widget.NavigationView> </android.support.v4.widget.DrawerLayout> 创建一个布局

  

custom_drawer_layout.xml

custom_drawer_layout

希望您能明白。
您可以看到一个相关项目here