【问题标题】:How to change the text of a menu?如何更改菜单的文本?
【发布时间】:2018-02-18 20:33:56
【问题描述】:

如何在 Android 中更改菜单的文本?我想更改显示“Welcome to Engineering”的文本,它是应用程序的名称,而不是当前膨胀的列表的名称。

Here is a picture of the Menu

这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.bignerdranch.android.welcometoengineering">

    <uses-feature android:name="android.hardware.camera"
                  android:required="false"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".CourseListActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <provider
            android:authorities="com.bignerdranch.android.welcometoengineering.fileprovider"
            android:name="android.support.v4.content.FileProvider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/files"/>
        </provider>
        <!--Hierarchies-->

        <activity
            android:name=".CoursePagerActivity"
            android:parentActivityName=".CourseListActivity">
        </activity>
        <activity
            android:name=".SemesterListActivity"
            android:parentActivityName=".CourseListActivity">
        </activity>
        <activity
            android:name=".ProfessorListActivity"
            android:parentActivityName=".SemesterListActivity">
        </activity>
        <activity
            android:name=".PostPagerActivity"
            android:parentActivityName=".ProfessorListActivity">
        </activity>
    </application>

</manifest>

这是布局 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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="match_parent">

<!-- Layer 1 -->
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/semester_recycler_view"/>


</FrameLayout>

这是该布局文件的菜单:

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

(我知道菜单目前没有任何作用。我会尽快更改。)

谢谢!

【问题讨论】:

    标签: android text menu title


    【解决方案1】:

    添加你的 onCreate

    this.setTitle("Your String");
    

    【讨论】:

    • 我应该把getter/setter放在哪里? “Welcome to Engineering”从未在除 Manifest 之外的任何地方明确设置。
    • 在这种情况下在您的工具栏上参考toolbar.setTitleEnabled(false);
    • 或者你可以在你的应用主题中为所有活动添加这个。 true
    • 抱歉,工具栏方法不起作用,因为这不是工具栏,而是菜单。我会尝试应用主题的方式并回复您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多