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>
Apostrofix
  • 2,140
  • 8
  • 44
  • 71
  • 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. – Lakhwinder Singh Sep 29 '15 at 06:23
  • have look at my answer and marked it as correct if it helped you. – waleedsarwar86 Sep 29 '15 at 06:29
  • Instead of setting `android:icon` in each `Activity`, set the `android:logo` instead. This will not affect the App Icon. – Joshua Pinter Oct 11 '19 at 15:37

1 Answers1

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>
waleedsarwar86
  • 2,354
  • 1
  • 19
  • 21
  • The problem is that when the label is empty, then the app name is not showing. – Apostrofix Sep 29 '15 at 06: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. – waleedsarwar86 Sep 29 '15 at 07:51
  • @Apostrofix i have updated my answer please check it let me know if it help. – waleedsarwar86 Sep 29 '15 at 07:56
  • @Apostrofix please marked it as correct if it worked – waleedsarwar86 Sep 29 '15 at 08: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 '15 at 09:20
  • @Apostrofix This answer doesn't properly use `android:logo` so it confuses other people landing here. The answer should be updated to reflect the usage of `android:logo` over `android:icon`. – Joshua Pinter Oct 11 '19 at 15:38