2

How to prevent Action bar from flickering when removing logo an setting title programatically

Below is the code I have in my MainActivity.java. This changes the action bar. But it first displays the actual action bar with logo and title I have given in Android Manifest.xml. Then the action bar flickers and changes to new title and no Logo.How to remove flickering and make Action bar load at once ?

ActionBar actionBar = getActionBar();
actionBar.setLogo(null);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("Welcome Dear User");
actionBar.setDisplayUseLogoEnabled(false);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

I tried with style.xml route also

Android Manifest.xml:

<application
        android:allowBackup="true"
        android:icon="@mipmap/geniusicon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:hardwareAccelerated="false"
        android:largeHeap="true"
        android:theme="@android:style/Theme.Holo.Light">
        <activity android:name=".MainActivity"
            android:theme="@style/AppTheme">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Style.xml:

 <style name="AppTheme" parent="@android:style/Theme.Holo.Light">
        <!-- Customize your theme here. -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>

    </style>

    <style name="MyActionBar" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:background">#20a780</item>
        <item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
    </style>

    <style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:textColor">#ff0000</item>
    </style>
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Bharath
  • 156
  • 1
  • 9
  • You can look at here. https://antonioleiva.com/collapsing-toolbar-layout/ – Aytek Sökmen Oct 02 '17 at 07:31
  • I think you didnt get my question. I am having a app. I have first page. In the first page, the action bar initially shows logo and title from Android Manifest.xml. But after that the action bar flickers and new action bar is shown. It doesnt have icon as I have removed it in java class. Is it possible to avoid this and have single action bar. – Bharath Oct 02 '17 at 08:06
  • Oh, i got it right now. Then, you should be create theme in styles.xml. Look at this. https://stackoverflow.com/a/18288460/5580210 – Aytek Sökmen Oct 02 '17 at 08:24
  • I tried that too. PFB my Android Manifests.xml and style.xml. But with this my action bar disappears. – Bharath Oct 02 '17 at 11:41

0 Answers0