为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

皈依舞 2023-02-23 10:14:10
所以我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>
查看完整描述

3 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

您获得了正确的 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"

    xmlns:local="http://schemas.android.com/apk/res-auto"

    android:id="@+id/toolbar"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:minHeight="?attr/actionBarSize"

    android:background="@drawable/toolbartitle" //either add a background here like this if it helps 

    local:theme="@style/MyMaterialTheme.Base"

    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

或者


 <android.support.v7.widget.Toolbar

                android:id="@+id/toolbar"

                android:layout_width="match_parent"

                android:layout_height="?attr/actionBarSize"

                android:background="@color/color_blue"

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


                <ImageView

                    android:id="@+id/tv_header_title"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_gravity="center"

                    android:src="@mipmap/header_title" />

            </android.support.v7.widget.Toolbar>


查看完整回答
反对 回复 2023-02-23
?
呼唤远方

TA贡献1856条经验 获得超11个赞

设计你自己的 ActionBar,或者简单地添加适当的

app:showAsAction="always"

在右侧菜单的 menu.xml 文件中.....


查看完整回答
反对 回复 2023-02-23
?
繁花不似锦

TA贡献1851条经验 获得超4个赞

菜单文件夹中以您的抽屉活动命名的菜单文件如下代码所示,您可以根据需要更改它


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

<menu xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item

        android:id="@+id/action_settings"

        android:orderInCategory="100"

        android:title="@string/action_settings"

        app:showAsAction="never" />

</menu>


查看完整回答
反对 回复 2023-02-23
  • 3 回答
  • 0 关注
  • 149 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号