如何使用默认的 Navigation Drawer Activity 将项目添加到

所以我NavigationDrawer在android studio中创建了默认的Activity。我的问题是我想添加一个小徽标或可能更改它,ActionBar但我似乎无法找到允许我这样做的 xml 文件。 我所说的 ActionBar 是什么意思

HomeActivity.java [此文件运行 Navigation Drawer Activity]

app_bar_home.xml [这是我认为包含对顶部栏的引用的文件]


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

<android.support.design.widget.CoordinatorLayout 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"

    tools:context=".HomeActivity">


    <android.support.design.widget.AppBarLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:theme="@style/AppTheme.AppBarOverlay">


        <android.support.v7.widget.Toolbar

            android:id="@+id/toolbar"

            android:layout_width="match_parent"

            android:layout_height="?attr/actionBarSize"

            android:background="@color/colorAccent"

            app:popupTheme="@style/AppTheme.PopupOverlay" />


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


    <include layout="@layout/content_home" />


    <android.support.design.widget.FloatingActionButton

        android:id="@+id/fab"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="bottom|end"

        android:layout_margin="@dimen/fab_margin"

        app:srcCompat="@android:drawable/ic_media_play" />


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


皈依舞
浏览 150回答 3
3回答

ABOUTYOU

您获得了正确的 XML,现在在 Toolbar 标记中执行类似的操作。1. 在工具栏中添加图像作为背景或 2. 在工具栏中添加 ImageView 标签<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; xmlns:local="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp; android:id="@+id/toolbar"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; android:minHeight="?attr/actionBarSize"&nbsp; &nbsp; android:background="@drawable/toolbartitle" //either add a background here like this if it helps&nbsp;&nbsp; &nbsp; local:theme="@style/MyMaterialTheme.Base"&nbsp; &nbsp; local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />或者&nbsp;<android.support.v7.widget.Toolbar&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/toolbar"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="?attr/actionBarSize"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:background="@color/color_blue"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app:popupTheme="@style/AppTheme.PopupOverlay">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/tv_header_title"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:src="@mipmap/header_title" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </android.support.v7.widget.Toolbar>

呼唤远方

设计你自己的 ActionBar,或者简单地添加适当的app:showAsAction="always"在右侧菜单的 menu.xml 文件中.....

繁花不似锦

菜单文件夹中以您的抽屉活动命名的菜单文件如下代码所示,您可以根据需要更改它<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; xmlns:app="http://schemas.android.com/apk/res-auto">&nbsp; &nbsp; <item&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/action_settings"&nbsp; &nbsp; &nbsp; &nbsp; android:orderInCategory="100"&nbsp; &nbsp; &nbsp; &nbsp; android:title="@string/action_settings"&nbsp; &nbsp; &nbsp; &nbsp; app:showAsAction="never" /></menu>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java