我正在尝试在Android的动作栏上做一些事情。
我已经在操作栏的右侧添加了新项目。
如何更改操作栏的左侧?我想改变图标和文本,我想在其他屏幕的操作栏中添加一个“返回按钮”
我正在尝试在Android的动作栏上做一些事情。
我已经在操作栏的右侧添加了新项目。
如何更改操作栏的左侧?我想改变图标和文本,我想在其他屏幕的操作栏中添加一个“返回按钮”
当前回答
我在onNavigationItemSelected内部使用了以下调用:
HomeActivity.this.setTitle(item.getTitle());
其他回答
要让一个图标可以被你所有的动作栏使用,你可以在你的Android Manifest中这样做。
<application
android:logo="@drawable/Image">
...
</application>
对于set Title:
getActionBar().setTitle("Title");
对于set图标:
getActionBar().setIcon(R.drawable.YOUR_ICON_NAME);
转到您想要更改操作栏标题名称并写入的特定活动的清单 android: label = "标题名称"
在Android 5.0中,材料设计指南不鼓励在actionBar中使用图标
要启用它,请添加以下代码
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
功劳归于这篇文章的作者
进入AndroidManifest.xml文件。 找到<application>标记 在这里您可以看到一个属性
android:label="@string/app_name"
现在转到res > values > strings.xml
改变
<string name="app_name">MainActivity</string>
to
<string name="app_name">Your Desired Name</string>
例子
AndroidManifest.xml
<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=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SubmitForm">
</activity>
</application>
strings.xml
<resources>
<string name="app_name">Your Desired Name</string>
<string name="action_settings">Settings</string>
</resources>