【问题标题】:How to change the launcher activity name and icon and keep the app name and icon?如何更改启动器活动名称和图标并保留应用程序名称和图标?
【发布时间】:2015-09-29 06:16:47
【问题描述】:

我希望在不同的活动中有不同的标题栏图标和名称,但不要更改应用程序名称或图标。第一个活动不应有标题名称。

这就是我在AndroidManifest.xml 中的内容:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:screenOrientation="portrait"
            android:name="" <!-- there should be no title here -->
            android:icon="@drawable/custom_icon"
            android:windowSoftInputMode="stateHidden|adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:screenOrientation="portrait"
            android:name=".MainActivity"
            android:icon="@drawable/another_custom_icon"
            android:label="MainTitle" >
        </activity>
</application>

显然Android 使用第一个活动的名称和图标作为应用名称和图标。 我知道我可以把这行代码放在activity的onCreate中:

    getActionBar().setTitle("");

但它也会在加载过程中显示,直到它被删除。

这是styles.xml 文件:

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/actionBarCustomization</item>
</style>

<style name="actionBarCustomization" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#FFFFFF</item>
    <item name="android:titleTextStyle">@style/actionBarTextColor</item>
</style>

<style name="actionBarTextColor" parent="@android:style/TextAppearance">
    <item name="android:textColor">#000000</item>
</style>

【问题讨论】:

  • 我认为活动不应该有一个图标,因为图标是代表完整的应用程序。并且name是activity类的路径,如果你不给,那么manifest会知道哪个类是activity。
  • 看看我的回答,如果对你有帮助的话,把它标记为正确。
  • 不是在每个Activity 中设置android:icon,而是设置android:logo。这不会影响应用图标。

标签: android android-actionbar android-titlebar


【解决方案1】:

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:screenOrientation="portrait"
       <!-- This the name on Activity so put there the name of your MainActivity i.e com.example.MainActivity -->
        android:name="NAME OF YOU LAUNCHER ACTIVITY"       
        android:icon="@drawable/custom_icon"
        android:theme="@style/Theme.NoActionBarTitle"
        android:windowSoftInputMode="stateHidden|adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:screenOrientation="portrait"
        android:name=".MainActivity"
        android:icon="@drawable/another_custom_icon"
        android:label="MainTitle" >
    </activity>

Style.xml

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    </style>
<style name="Theme.NoActionBarTitle" parent="@android:style/Theme.Holo.Light">
  <item name="android:actionBarStyle">@style/NoActionBarTitle.ActionBar</item>
</style>

 <style name="NoActionBarTitle.ActionBar"    parent="@android:style/Widget.Holo.Light.ActionBar">
  <<item name="android:displayOptions">showHome|useLogo</item>
 </style>

之后你可以通过使用方法显示活动的标题。

 getActionBar().setDisplayShowTitleEnabled(true);

对于那些正在使用 appcompat 支持库的人。我的意思是,活动是从 AppCompatActivity 扩展的,请使用以下样式文件

Style.xml(如果您使用的是 appcompat)

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="Theme.NoActionBarTitle" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/NoActionBarTitle.ActionBar</item>
    <item name="android:actionBarStyle">@style/NoActionBarTitle.ActionBar</item>
</style>

<style name="NoActionBarTitle.ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:displayOptions">showHome|useLogo</item>
    <item name="displayOptions">showHome|useLogo</item>
</style>

【讨论】:

  • 问题是label为空的时候,app名称不显示。
  • @Apostrofix 抱歉,我现在明白您的问题是启动器中的应用名称也被删除了,我已经编辑了我的代码,希望对您有所帮助。
  • @Apostrofix 我已经更新了我的答案,请检查它让我知道是否有帮助。
  • @Apostrofix 如果有效,请将其标记为正确
  • 谢谢!现在工作正常。总而言之,为了在启动器活动的标题栏中使用不同的应用程序图标,我必须:在清单中设置应用程序图标,然后删除活动图标并设置活动徽标。
猜你喜欢
  • 2018-04-23
  • 2019-03-03
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 2020-12-25
  • 1970-01-01
  • 1970-01-01
  • 2014-08-12
相关资源
最近更新 更多