2

I would like to have different title bar icons and names in the different activities, but not to change the app name or icon. The first activity should not have a title name.

This is what I have in the 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>

Apparently Android uses the name and the icon of the first activity for the app name and icon. I know that I can put this line of code in the onCreate of the activity:

    getActionBar().setTitle("");

But it is also shown during load, until it gets removed.

This is the styles.xml file:

<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>
3
  • i think activity should not have an icon, because icon is for representing the complete application. And name is for the path of the activity class, if you not give that, then how manifest will know that which class is the activity. Sep 29, 2015 at 6:23
  • have look at my answer and marked it as correct if it helped you. Sep 29, 2015 at 6:29
  • Instead of setting android:icon in each Activity, set the android:logo instead. This will not affect the App Icon. Oct 11, 2019 at 15:37

1 Answer 1

3

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>

After That you can show the title of activity if you want to By using method.

 getActionBar().setDisplayShowTitleEnabled(true);

For Those who are using appcompat support library.I mean there activites are extending from AppCompatActivity use the below style file

Style.xml if you are using 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>
6
  • The problem is that when the label is empty, then the app name is not showing.
    – Apostrofix
    Sep 29, 2015 at 6:58
  • @Apostrofix Sorry i now understand your problem was the app name from launcher also removed i have edit my code and i hope it will help. Sep 29, 2015 at 7:51
  • @Apostrofix i have updated my answer please check it let me know if it help. Sep 29, 2015 at 7:56
  • @Apostrofix please marked it as correct if it worked Sep 29, 2015 at 8:07
  • 1
    Thank you! It is working fine now. To summarize, in order to have a different app icon than the one in the title bar of the launcher activity, I had to: set the app icon in the manifest, then I removed the activity icon and set the activity logo.
    – Apostrofix
    Sep 29, 2015 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.