I'm trying to create a swipe view as described here http://developer.android.com/training/implementing-navigation/lateral.html
I've created an action bar as per the documentation with final ActionBar actionBar = getActionBar();
but I get the following message
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setNavigationMode(int)' on a null object reference
which relates to this line actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Now i've established that it's likely to do with my theme not having an action bar, see android:theme="@style/Theme.AppCompat.Light.NoActionBar">
, so I change my theme to say android:theme="@style/Theme.AppCompat.Light">
, but then I get the following message:
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead
and all the answers on the internet say to change to a non action bar theme, which gives me the first error again. So I'm literally going around in circles. I want to basically have this action bar with tabs as described in the documentation.
This theme already has ActionBar
:
android:theme="@style/Theme.AppCompat.Light"
And of course, you are trying to use the old ActionBar
with AppCompat
theme.
So, you will need to use Theme.Holo
for that the old ActionBar
or if you are using Theme.AppCompat
, you need to use it with getSupportActionBar
like this:
actionbar = getSupportActionBar();
Check this question: actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) deprecated
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.