如何为启动器而不是活动标题设置不同的标签? [英] How to set different label for launcher rather than activity title?

查看:100
本文介绍了如何为启动器而不是活动标题设置不同的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题以前曾被问过-但根本没有令人满意的答案!所以我再试一次.

This question has been asked before - but with no satisfying answer at all! So I'm trying it again.

我想给我的应用程序启动器图标(在开始屏幕上显示的图标)一个不同的较短标题.似乎启动程序从mainfest部分获取有关主要活动标签的标签,如下所示:

I want to give my application launcher icon (the one that is displayed on the startscreen!) a different, shorter caption. It seems the launcher takes its label from the mainfest section about the main activity's label, as here:

<activity android:name="MainActivity" android:label="@string/app_short_name">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

我已经将对应用程序名称@ string/app_name的原始引用更改为此处的另一个较短的字符串资源.

I already changed the original reference to my app's name @string/app_name to a different, shorter string resource here.

但-大:当然,这也会更改此活动的默认标题!而且我不希望这种情况发生,因为有足够的空间来容纳较长的应用程序名称!使用setTitle(int)方法在onCreate中再次设置长标题也无济于事,因为短名称将在短时间内对用户可见,但足以引起注意!

BUT - big BUT: this also of course changes this activity's default title! And I did not want that to happen, there's enough space for a long application name! Setting the long title again in onCreate using the setTitle(int) method does no good either, because the short name will be visible to the user for a short time, but long enough to notice!

而且-请不要通过引用自定义标题栏来回答我的问题...我不想走那么长的路,仅仅是因为一个愚蠢的字符串标题!绘制自定义标题栏效果太差了!

And - please don't answer my question by refering to a custom titlebar... I do not want to go that long way, just because of a stupid string title! It's a pain to draw a custom title bar for so little effect!

有没有简单的方法,只是给启动器显示不同的字符串? 感谢您的回答!

Is there no easy way to just give the launcher a different string to display? Thanks for your answers!

拥有自定义标题栏的另一个麻烦是它看起来不会像默认标题栏,我必须明确地做一些事情才能使它在每台设备上看起来都一样!如果毕竟我不想要其他外观,那将不是解决方案!

One more reason why having a custom titlebar is a pain is that it will not look like the default titlebar, I would have to explicitly do things to make it look alike on each device! And that can't be a solution if, after all, I don't want a different appearance!

推荐答案

显然,<intent-filter>可以具有标签属性.如果不存在,则标签将从父组件(活动"或应用程序")继承.因此,使用此功能,您可以为启动器图标设置标签,同时仍将活动"作为其自己的标题.

Apparently <intent-filter> can have a label attribute. If it's absent the label is inherited from the parent component (either Activity or Application). So using this, you can set a label for the launcher icon, while still having the Activity with it's own title.

请注意,尽管此方法可在仿真器上运行,但可能无法在实际设备上运行,因为它取决于所使用的启动器实现.

Note that, while this works on emulators, it might not work on real devices, because it depends on the launcher implementation that is used.

http://developer.android.com/guide/topic/manifest/intent-filter-element.html

<activity
  android:name=".ui.HomeActivity"
  android:label="@string/title_home_activity"
  android:icon="@drawable/icon">
  <intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

侧面说明:< intent-filter>也可以具有icon属性,但是 莫名其妙地,它会覆盖 活动.如果您打算使用本机,这对您可能很重要 SDK 11+中的ActionBar,它使用在 活动.

Side Note: <intent-filter> can also have an icon attribute, but inexplicably it does not override the icon specified in the Activity. This may be important to you if you plan to use the native ActionBar in SDK 11+, which uses Icon and Logo specified on the Activity.

添加的信息:该标签是从活动"而不是应用程序"继承的.

Added Info: The label is being inherited from Activity and not the Application.

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"       
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".StartActivity"
            android:label="@string/app_long_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

在这种情况下,如果我们没有如上所述将标签放在其中,则app_long_name将显示启动器图标.

In this case, app_long_name will be displayed with launcher icon, if we do not put label inside as mentioned above.

这篇关于如何为启动器而不是活动标题设置不同的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆