Currently, I am using ActionBarSherlock. I want to launch SecondActivity
from MainActivity
.
MainActivity
is using action bar with windowActionBarOverlay
style turned on. SecondActivity
is using action bar with windowActionBarOverlay
style turned off. Hence, here is how my XML looks like.
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="false" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/ThemeWithActionBarOverlay"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="@style/ThemeWithoutOverlay">
</activity>
</application>
<resources>
<style name="ThemeWithActionBarOverlay" parent="@style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">true</item>
<item name="abIcon">@drawable/ic_home</item>
<item name="abTitleTextStyle">@style/ActionBarCompatTitle</item>
</style>
<style name="ThemeWithoutOverlay" parent="@style/Theme.Sherlock">
<item name="abIcon">@drawable/ic_home</item>
<item name="abTitleTextStyle">@style/ActionBarCompatTitle</item>
</style>
</resources>
However, by doing so, in SecondActivity
, I realize I can never have a up/back button on the top left of action bar. Although there is icon being shown, it is not pressable. Only by using back same theme (ThemeWithActionBarOverlay) as MainActivity
, only up/back button will shown. However, if I let SecondActivity
to use same theme as MainActivity
, I find out no way to turn off windowActionBarOverlay
behaviour.
// SecondActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history_list_activity);
ActionBar actionBar = this.getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
// How to turn android:windowActionBarOverlay attribute to false during runtime?
// actionBar.???
}
My questions are
windowActionBarOverlay
style during runtime?To answer your first question, you don't need to have the parent and child activity using the same theme for the 'Up' button to work. In fact, I'm working on a similar parent/child activity application, and its working just fine using two different themes( a theme without overlay for the parent, and the fullscreen theme (with overlay) for the child).
There must be another reason why it is not working...
Make sure you have defined MainActivity to be the parent of second activity. You can do that either by code, or the prefered way, in the AndroidManifest.xml:
<activity
android:name=".SecondActivity"
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Make sure that in your child activity, you have activated the 'up' navigation:
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
For your second question, try overriding the 'windowActionBarOverlay' in the 'ThemeWithoutOverlay' theme to false:
<style name="ThemeWithoutOverlay" parent="@style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">false</item>
<item name="windowActionBarOverlay">false</item><
<item name="abIcon">@drawable/ic_home</item>
<item name="abTitleTextStyle">@style/ActionBarCompatTitle</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With