问题
I have an Android tabbed app. I don't want anything else other than the tabs to be displayed at the top of the screen.
This works alright, the only problem is that, when launching the app, for a short moment < 1sec, I can see the title bar with the application launcher icon.
Why is this happening, is there a way to prevent this?
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
</style>
<style name="CustomActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/NoTitleText</item>
<item name="android:subtitleTextStyle">@style/NoTitleText</item>
<item name="android:icon">@android:color/transparent</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
</resources>
AndroidManifest.xml
<activity
android:name="com.example.nfcproducttracing.ProductTracer"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:launchMode="singleTask">
This makes my tab text white and barely visible.
回答1:
To prevent this you must use styles defined in xml file insted of seting everything in your onCreate method.
Before this line in code is execued
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
your application is already visible.
Try this:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">@style/CustomActionBarStyle</item>
</style>
<style name="CustomActionBarStyle" parent="@style/Widget.Holo.ActionBar">
<item name="titleTextStyle">@style/NoTitleText</item>
<item name="subtitleTextStyle">@style/NoTitleText</item>
<item name="icon">@android:color/transparent</item>
</style>
<style name="NoTitleText">
<item name="textSize">0sp</item>
<item name="textColor">#00000000</item>
</style>
</resources>
来源:https://stackoverflow.com/questions/20612231/actionbar-with-notitlebar-theme-holo-light