I have a split action bar, where the top bar is dark and the bottom bar (split) is light.
Consequently, I'd like to show a contrast action icons: Light icons in the top dark bar and dark icons in the bottom light bar.
The problem is knowing if the actions should be painted on the top or bottom bar. How can I know that?
Another option is to know whether the action bar is currently split. How do I know that?
Thanks.
Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.
The ActionBar, now known as the App Bar, is a consistent navigation element that is standard throughout modern Android applications. The ActionBar can consist of: An application icon. An "upward" navigation to logical parent.
All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
In its most basic form, the action bar displays the title for the activity on one side and an overflow menu on the other. Even in this simple form, the app bar provides useful information to the users, and helps to give Android apps a consistent look and feel.
Simple. You use boolean values. By default you'll have a split ActionBar if the screen width is smaller than 400dp. So in your values folder you can put:
/values/bools.xml:
<resources>
<bool name="split_action_bar">true</bool>
</resources>
and in your values-sw400dp you put the following.
/values-sw400dp/bools.xml:
<resources>
<bool name="split_action_bar">false</bool>
</resources>
Now you can set your icon based on that value:
boolean isActionBarSplitted = getResources().getBoolean(R.bool.split_action_bar);
if(isActionBarSplitted){
// set light icon
}
else{
// set dark icon
}
Edit:
Actually forget what I wrote, you don't need to create your own boolean value to check it. There is already one declared(which is the one the ActionBar uses to determine if it is a handset device or a tablet).
If you're targeting Android HC+, then you can access the default ActionBars value:
android.R.bool.split_action_bar_is_narrow
, if you are using ActionBarSherlock:
R.bool.abs_split_action_bar_is_narrow
.
Found here for the default ActionBar, here your ABS.
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