我们如何解决actionbar getactionbar函数中的null excaption?

时间:2015-06-28 17:29:45

标签: android-actionbar

首先我想说我是android的新手,我在Android操作栏上遇到了很多麻烦我试图在这一行上没有得到null:

ActionBar actionBar = getActionBar();

我尝试了一切。我知道它返回null,因为主题不适合活动的主题。我不知道如何为每个主题设置不同的主题,但在我找到避免这个问题的方法后,我又遇到了另一个问题。我想要做的是操作栏和标签栏,现在我看不到操作栏中的图标,我在溢出中看到它们。

的onCreate:

public class MainViewActivity extends Activity implements RoutesFragment.OnFragmentInteractionListener ,GroupsFragment.OnFragmentInteractionListener
            ,VideosFragment.OnFragmentInteractionListener,PhotosFragment.OnFragmentInteractionListener
    {

        private final CharSequence charSequence[] = {"Profile", "New route", "My route", "Liked route", "GroupsFragment", "Settings", "About CTwalk"};
        private String charSequence2;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_view);
            getOverflowMenu();
            ActionBar actionBar = getActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);

            Tab tab = actionBar.newTab()
                    .setText(R.string.tabs_Routes)
                    .setTabListener(new TabListener<RoutesFragment>(this, "Routes", RoutesFragment.class));
            actionBar.addTab(tab);

            tab = actionBar.newTab()
                    .setText(R.string.tabs_Groups)
                    .setTabListener(new TabListener<GroupsFragment>(
                            this, "GroupsFragment", GroupsFragment.class));
            actionBar.addTab(tab);

            tab = actionBar.newTab()
                    .setText(R.string.tabs_Photos)
                    .setTabListener(new TabListener<PhotosFragment>(
                            this, "PhotosFragment", PhotosFragment.class));
            actionBar.addTab(tab);


            tab = actionBar.newTab()
                    .setText(R.string.tabs_Videos)
                    .setTabListener(new TabListener<VideosFragment>(
                            this, "VideosFragment", VideosFragment.class));
            actionBar.addTab(tab);

        }

Android manidest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ctwalkapp.ctwalk" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" >
        </activity>
        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <activity
            android:name=".MainViewActivity"
            android:label="@string/title_activity_main_view"
            android:parentActivityName=".LoginActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".LoginActivity" />
        </activity>
    </application>

</manifest>

styles.xml:

<resources>
    <style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:windowActionBar">true</item>
    </style>
<style name= "MyCustomTheme" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#3f51b5</item>
        </style>
</resources>

0 个答案:

没有答案