本文介绍了Android的启动标签与活动名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问过 - 但没有令人满意的答案了!所以我再次尝试它。

我想给我的应用程序启动器图标(上显示的启动画面的一个!)不同,短标题。看来发射器采用其标签,从对主要活动的标签mainfest部分,如下:

 <活动机器人:名称=MainActivity机器人:标签=@字符串/ app_short_name>
<意向滤光器>
    <作用机器人:名称=android.intent.action.MAIN/>
    <类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
 

我已经改变了原来的引用我的应用程序的名称@字符串/ APP_NAME到一个不同的,较短的字符串这里的资源。

但是 - 大的可是:这当然也改变了本次活动的默认的标题!而且我不希望这种情况发生,有足够的空间,长期应用程序名!使用的setTitle(INT)方法的onCreate 重新设定长的标题确实没有好或者,因为短域名会是可见的很短的时间的用户,但足够长以通知!

和 - 请不要回答我的提问指的是一个自定义标题栏......我不想去,只是因为一个愚蠢的字符串的标题,很长的路要走,!这是一个痛苦的画一个自定义标题栏所以影响不大!

没有简单的方法就这样给发射一个不同的字符串来显示?谢谢您的回答!

编辑:还有一个原因,有一个自定义标题栏是一个痛苦的是,它不会像默认的标题栏,我会明确地做事情,使它看起来很像在每台设备上!这不可能是一个解决方案,如果,毕竟,我不希望有一个不同的外观!

解决方案

解决方案找到了!

显然<意图过滤器>可以拥有一个标签属性。如果它是不存在的标签从父组件(或者活动或应用程序)继承。所以用这个,你可以设置为启动器图标的标签,同时还具有与它自己的标题活动。

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

 <活动
  机器人:名称=。ui.HomeActivity
  机器人:标签=@字符串/ title_home_activity
  机器人:图标=@可绘制/图标>
  <意图过滤器的Andr​​oid版本:标签=@字符串/ APP_NAME>
    <作用机器人:名称=android.intent.action.MAIN/>
    <类机器人:名称=android.intent.category.LAUNCHER/>
  &所述; /意图滤光器>
< /活性GT;
 

新增信息:为活动的继承的标签,而不是应用程序

 <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>

        <活动
            机器人:名称=。StartActivity
            机器人:标签=@字符串/ app_long_name>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
 

在这种情况下,app_long_name将与发射器图标显示出来,如果​​我们不把标签内,如上所述。

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

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>

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

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!

Edit: 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!

解决方案

Solution found!

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.

http://developer.android.com/guide/topics/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>

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>

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

这篇关于Android的启动标签与活动名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:51
查看更多