Android layout 在android应用程序中添加工具栏

Android layout 在android应用程序中添加工具栏,android-layout,listview,android-studio,android-fragments,Android Layout,Listview,Android Studio,Android Fragments,我想在android应用程序中添加工具栏,但在将应用程序推到git上后,在运行时StudentDashboardActivity.java中出现此错误。我找不到它背后的问题 FATAL EXCEPTION: main Process: com.technerdshub.vusocial, PID: 31319 java.lang.RuntimeException: Unable to start activity ComponentInfo

我想在android应用程序中添加工具栏,但在将应用程序推到git上后,在运行时StudentDashboardActivity.java中出现此错误。我找不到它背后的问题

FATAL EXCEPTION: main
              Process: com.technerdshub.vusocial, PID: 31319
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.technerdshub.vusocial/com.technerdshub.vusocial.Activities.StudentDashboardActivity}: 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.
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
              at android.app.ActivityThread.access$900(ActivityThread.java:177)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:145)
              at android.app.ActivityThread.main(ActivityThread.java:5942)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at

              com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
              Caused by: 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.
              at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:198)
              at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
              at com.technerdshub.vusocial.Activities.StudentDashboardActivity.onCreate(StudentDashboardActivity.java:51)
              at android.app.Activity.performCreate(Activity.java:6289)
StudentDashboardActivity.java

package com.technerdshub.vusocial.Activities;

    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.design.widget.TabLayout;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.support.v7.app.ActionBarActivity;
    import android.support.v7.widget.Toolbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;

    import com.google.android.gms.appindexing.Action;
    import com.google.android.gms.appindexing.AppIndex;
    import com.google.android.gms.common.api.GoogleApiClient;
    import com.technerdshub.vusocial.Fragments.TaskFragment;
    import com.technerdshub.vusocial.Fragments.dummy.DummyContent;
    import com.technerdshub.vusocial.R;

    import java.util.ArrayList;
    import java.util.List;

    public class StudentDashboardActivity extends AppCompatActivity {

        private Toolbar toolbar;
        private TabLayout tabLayout;
        private ViewPager viewPager;
        /**
         * ATTENTION: This was auto-generated to implement the App Indexing API.
         * See https://g.co/AppIndexing/AndroidStudio for more information.
         */
        private GoogleApiClient client;

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            displayLoginActivity();

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_student_dashboard);

    //        Parse.initialize(new Parse.Configuration.Builder(this)
    //                        .applicationId("J5CIV2z6xeSCXDqdOfhE0kPSikvRFPyDyOJxqJNx")
    //                        .clientKey("bEWm4nWtWiBrMczGfOvA7s4Ulr2bAU3W3TtVSLDf")
    //                        .build()
    //        );
            toolbar = (Toolbar) findViewById(R.id.tool_bar);
            setSupportActionBar(toolbar);

            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setElevation(2);


            viewPager = (ViewPager) findViewById(R.id.viewpager);
            setupViewPager(viewPager);

            tabLayout = (TabLayout) findViewById(R.id.tabs);
            tabLayout.setupWithViewPager(viewPager);

    //        ParseObject testObject = new ParseObject("Task");
    //        testObject.put("marks", 99);
    //        testObject.saveInBackground();

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
        }

        private void setupViewPager(ViewPager viewPager) {
            ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
            adapter.addFragment(new TaskFragment(), "Quiz");
            adapter.addFragment(new TaskFragment(), "Assignment");
            adapter.addFragment(new TaskFragment(), "GDB");
            viewPager.setAdapter(adapter);
        }



        private void displayLoginActivity() {

            Intent i = new Intent(this, Login.class);
            startActivity(i);

        }

        @Override
        public void onStart() {
            super.onStart();

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            client.connect();
            Action viewAction = Action.newAction(
                    Action.TYPE_VIEW, // TODO: choose an action type.
                    "StudentDashboard Page", // TODO: Define a title for the content shown.
                    // TODO: If you have web page content that matches this app activity's content,
                    // make sure this auto-generated web page URL is correct.
                    // Otherwise, set the URL to null.
                    Uri.parse("http://host/path"),
                    // TODO: Make sure this auto-generated app URL is correct.
                    Uri.parse("android-app://com.technerdshub.vusocial.Activities/http/host/path")
            );
            AppIndex.AppIndexApi.start(client, viewAction);
        }

        @Override
        public void onStop() {
            super.onStop();

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            Action viewAction = Action.newAction(
                    Action.TYPE_VIEW, // TODO: choose an action type.
                    "StudentDashboard Page", // TODO: Define a title for the content shown.
                    // TODO: If you have web page content that matches this app activity's content,
                    // make sure this auto-generated web page URL is correct.
                    // Otherwise, set the URL to null.
                    Uri.parse("http://host/path"),
                    // TODO: Make sure this auto-generated app URL is correct.
                    Uri.parse("android-app://com.technerdshub.vusocial.Activities/http/host/path")
            );
            AppIndex.AppIndexApi.end(client, viewAction);
            client.disconnect();
        }

        class ViewPagerAdapter extends FragmentPagerAdapter {
            private final List<TaskFragment> mFragmentList = new ArrayList<>();
            private final List<String> mFragmentTitleList = new ArrayList<>();

            public ViewPagerAdapter(FragmentManager manager) {
                super(manager);
            }

            @Override
            public TaskFragment getItem(int position) {
                return mFragmentList.get(position);
            }

            @Override
            public int getCount() {
                return mFragmentList.size();
            }

            public void addFragment(TaskFragment fragment, String title) {
                mFragmentList.add(fragment);
                mFragmentTitleList.add(title);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mFragmentTitleList.get(position);
            }


        }

    }
package com.technerdshub.vusocial.Activities;
导入android.app.Activity;
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.support.design.widget.TabLayout;
导入android.support.v4.app.FragmentManager;
导入android.support.v4.app.FragmentPagerAdapter;
导入android.support.v4.view.ViewPager;
导入android.support.v7.app.ActionBarActivity;
导入android.support.v7.widget.Toolbar;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入com.google.android.gms.appindexing.Action;
导入com.google.android.gms.AppIndex.AppIndex;
导入com.google.android.gms.common.api.GoogleAppClient;
导入com.technerdshub.vusocial.Fragments.TaskFragment;
导入com.technerdshub.vusocial.Fragments.DummyContent;
导入com.technerdshub.vusocial.R;
导入java.util.ArrayList;
导入java.util.List;
公共类StudentDashboardActivity扩展了AppCompatActivity{
专用工具栏;
私人摊位摊位;
私人视页机视页机;
/**
*注意:这是自动生成的,用于实现应用程序索引API。
*看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
*/
私人谷歌客户;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
displayLoginActivity();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u student\u仪表板);
//初始化(新的Parse.Configuration.Builder(此)
//.applicationId(“J5CIV2Z6XESCxDqdofH0KPSIKVRFPYDYOJXQJNx”)
//.clientKey(“bEWm4nWtWiBrMczGfOvA7s4Ulr2bAU3W3TtVSLDf”)
//.build()
//        );
工具栏=(工具栏)findViewById(R.id.tool\u栏);
设置支持操作栏(工具栏);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setElevation(2);
viewPager=(viewPager)findViewById(R.id.viewPager);
设置viewPager(viewPager);
tabLayout=(tabLayout)findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
//ParseObject testObject=新的ParseObject(“任务”);
//testObject.put(“marks”,99);
//testObject.saveInBackground();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client=new GoogleApiClient.Builder(this.addApi(AppIndex.API).build();
}
专用无效设置ViewPager(ViewPager ViewPager){
ViewPagerAdapter适配器=新的ViewPagerAdapter(getSupportFragmentManager());
addFragment(new TaskFragment(),“quick”);
addFragment(新的TaskFragment(),“赋值”);
addFragment(新的TaskFragment(),“GDB”);
viewPager.setAdapter(适配器);
}
私有void displayLoginActivity(){
意图i=新意图(这个,Login.class);
星触觉(i);
}
@凌驾
public void onStart(){
super.onStart();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client.connect();
Action viewAction=Action.newAction(
Action.TYPE\u视图,//TODO:选择一种操作类型。
“StudentDashboard页面”//TODO:为显示的内容定义标题。
//TODO:如果您的网页内容与此应用程序活动的内容匹配,
//确保此自动生成的网页URL正确无误。
//否则,请将URL设置为null。
解析http://host/path"),
//TODO:确保此自动生成的应用程序URL正确。
解析-app://com.technerdshub.vusocial.Activities/http/host/path")
);
AppIndex.AppIndexApi.start(客户端,viewAction);
}
@凌驾
公共void onStop(){
super.onStop();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
Action viewAction=Action.newAction(
Action.TYPE\u视图,//TODO:选择一种操作类型。
“StudentDashboard页面”//TODO:为显示的内容定义标题。
//TODO:如果您的网页内容与此应用程序活动的内容匹配,
//确保此自动生成的网页URL正确无误。
//否则,请将URL设置为null。
解析http://host/path"),
//TODO:确保此自动生成的应用程序URL正确。
解析-app://com.technerdshub.vusocial.Activities/http/host/path")
);
AppIndex.AppIndexApi.end(客户端,viewAction);
client.disconnect();
}
类ViewPagerAdapter扩展了FragmentPagerAdapter{
私有最终列表MFFragmentList=new ArrayList();
私有最终列表MFFragmentTitleList=new ArrayList();
公共视图页面编辑器(碎片管理器){
高级经理;
}
@凌驾
公共任务片段getItem(int位置){
<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>



    </style>

    <!--<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">-->
        <!--<item name="windowActionBar">false</item>-->
        <!--<item name="windowNoTitle">true</item>-->



    <!--</style>-->

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >

    </style>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="TEST" parent="AppTheme" >
        <item name="colorPrimary">@color/com_facebook_blue</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/cardview_light_background</item>
        <item name="colorPrimaryDark">@color/com_facebook_button_background_color_selected</item>
    </style>


    <!--&lt;!&ndash; new design fai&ndash;&gt;-->
    <!--<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">-->

    <!--</style>-->

    <!--<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">-->
        <!--<item name="windowNoTitle">true</item>-->
        <!--<item name="windowActionBar">false</item>-->
        <!--<item name="colorPrimary">@color/colorPrimary</item>-->
        <!--<item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
        <!--<item name="colorAccent">@color/colorAccent</item>-->
    <!--</style>-->


</resources>
<item name="windowActionBar">false</item> 
 <item name="windowNoTitle">true</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>