Getsupportactionbar Return Null
After I started my second Activity, there isn't the ActionBar. When I call GetSupportActivity, it returns null. Why? I have minSdkVersion 10 and targetSdkVersion 15.
Solution 1:
for the problem getSupportActionBar() always return NULL That is because you set theme NoActionBar in AndroidManifest.xml
Theme.Sherlock.Light.NoActionBar
If your application does not use action bar then no need use that method.
Solution 2:
I havent played around with SherlockListActivity too much...but here's a shot in the dark....try moving
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
into your onStart method override instead of the onCreate
Solution 3:
if you're using toolbar in a separate xml file without any layout, then getSupportActionBar() will return null. To avoid this error, just place your toolbar inside a layout.
<?xml version="1.0" encoding="utf-8"?><LinearLayoutandroid:layout_width="match_parent"android:layout_height="?attr/actionBarSize"xmlns:app="http://schemas.android.com/apk/res-auto"android:orientation="horizontal"xmlns:android="http://schemas.android.com/apk/res/android"><!-- Toolbar --><android.support.v7.widget.Toolbarandroid:id="@+id/my_toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/colorPrimary"android:theme="@style/AppTheme.CustomThemeOverlay"app:popupTheme="@style/AppTheme.PopupOverlay"app:layout_scrollFlags="scroll|enterAlways|snap" /></LinearLayout>
put below code in your style.xml file
<stylename="AppTheme.CustomThemeOverlay"parent="ThemeOverlay.AppCompat.ActionBar"/><stylename="AppTheme.PopupOverlay"parent="ThemeOverlay.AppCompat.Light"/>
This solution worked for me. And I hope this may help someone. :)
Post a Comment for "Getsupportactionbar Return Null"