Android:以编程方式更改应用程序标签
如何更改应用程序标签以更改 Android 中 java 代码显示的应用程序名称? 我指的是:
<application android:icon="@drawable/icon" android:label="@string/app_name">
在 Android Manifest 中,
有没有办法更新 strings.xml 文件中的值?
How can I change application label to change app name shown from java code in android?
I'm refering to:
<application android:icon="@drawable/icon" android:label="@string/app_name">
in the Android Manifest
Is there any way to update values in strings.xml file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在活动中,我尝试了
并且有效。我希望这是一个通用的解决方案
in the activity, i tried
and it worked. I hope it's a common solution
暂时还不可能。它是 AndroidManifest.xml 文件中的固定字符串,无法在运行时更改。
It's not possible by the moment. It is a fixed string in the AndroidManifest.xml file which cannot be changed at runtime.
使用
您可以将应用程序图标和名称更改为您预定义的几个。在
Mannifest.xml
中创建此类配置现在您可以在这两个别名之间切换,因此我们将更改应用程序图标或/和名称。
要从默认切换到风味一,请使用此代码。
请记住,您必须跟踪一次仅启用一个别名
Using
<activity-alias>
you can change App icon and name to few predefined by you.Create such config in
Mannifest.xml
Now you can switch between those two aliases, therefore we will change app icon or/and name.
To switch from Default to Flavor-One use this code.
Keep in mind that you have to track that only one alias will be enabled at a time
在Launcher Activity中,在
setContentView()
写这个之前,我不知道这是怎么可能的,但它肯定有效。
In Launcher Activity,Before
setContentView()
write this,I don't know how it's possible, But it's surely works.
是的,有可能,在这个问题中,每个人都提到这样
只会更改您的活动名称而不是应用程序徽标,这里我向您展示如何动态更改应用程序徽标和应用程序名称
首先在 mipmap 中添加动态应用程序图标文件夹,然后在您的
AndroidManifest.xml
文件中添加以下代码为您的应用程序图标添加
执行这些方法后在您的活动中,只需执行以下操作单击按钮
了解更多详细信息,请参阅此 github 项目
Yes, Its possible, In this question everyone mentioned like
this will change only your activity name not app logo here I show you how to change the app logo and appname dynamicly
First add your dynamic app icons in the mipmap folder , after that add the below code in your
AndroidManifest.xml
fileAdd
<activity-alias>
for your app iconAfter doing these methods on your activity, just do below things on button click
for more details refer this github project
应用程序的 android:label 是固定资源引用者。
但是,根据配置限定符名称(values-en、-large、-land 等),此引荐来源网址下的字符串可能有多个值
提供替代资源。
Application's android:label is a fixed resource referrer.
But the string under this referrer could have multiple values, depending on configuration qualifier names (values-en, -large, -land, etc.), according to
Providing Alternative Resources.
对于任何感兴趣的人:Android 如何更改应用程序标题
但尚不清楚它是否更改了“应用程序标签”(即应用程序列表中的图标名称)或仅更改了窗口标题。
To anyone interested: Android How to change the application title
But it's not clear if it changes the "application label" (that is, the name of the icon in the application list) or only the window title.
如果您要扩展固件,实际上可以通过更改 IconCache.java 文件并使其显示带有手机某些内部值的字符串来完成此操作。
例如,如果您希望 SIM 工具包显示运营商的名称,您可以这样做。
但正如所说,对于常规应用程序来说,目前还不可能。
If you are extending the firmware, you can actually accomplish this by changing IconCache.java file and make it show a string with some internal value of the phone.
For example if you want the SIM Toolkit to show the name of the carrier, you can do that this way.
But for regular apps, as it's been said, it's currently not posible.
正如史密斯先生所说,这是不可能的,
但您可以使用多个
ActivityAlias
,它们可以动态启用/禁用并指向相同的targetActivity。因此,为应用程序名称创建选择器 - 让用户选择一个并通过packageManager
启用ActivityAlias
:要隐藏旧别名,请使用带有标志的相同代码:
COMPONENT_ENABLED_STATE_DISABLED
在启用别名后,您还可以添加直接添加主启动器快捷方式的可能性。这里有很多关于母猪的方法。
As Mister Smith said, it is not possible,
but you could use multiple
ActivityAlias
, which can be enabled/disabled dynamically and point to the same targetActivity. Therefore create your chooser for the app name - let the user select one and enable theActivityAlias
via thepackageManager
:To hide the old alias, use the same code with the flag :
COMPONENT_ENABLED_STATE_DISABLED
You can also add the possibility to directly add a shortcut to the home launcher, after you enabled the alias. There are plenty ways described here on sow.