材料抽屉在Eclipse ISSE [英] Material Drawer In Eclipse Isse

查看:151
本文介绍了材料抽屉在Eclipse ISSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加材料在抽屉Android应用程序......所以我们需要,我们必须包括一个工具栏..
但是,当我们包括工具栏我得到错误
我的code为activitymain_xml是

i want to add material drawer in android app ...so we need we have to include a toolbar .. but when we include toolbar i got error my Code for activitymain_xml is

       <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_parent_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:fitsSystemWindows="true">

        <include layout="@layout/toolbar"/>


    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
           </FrameLayout>

        <!-- The navigation drawer -->
      <ListView android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="#004869"
            android:textSize="20sp"
            android:dividerHeight="1dp"
            android:background="#fff"
            android:textColor="#f9f5f5"
            android:paddingLeft="15sp"
            android:paddingRight="15sp"
            android:paddingTop="10dp"
            />

          </android.support.v4.widget.DrawerLayout>

         </LinearLayout>

code为工具栏

code for toolbar is

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="@drawable/toolbar_background"/>

code为包括工具栏

code for include toolbar is

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

我Style.xml是

My Style.xml is

    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
     <item name="windowActionBar">false</item> 
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">

    </style>

   </resources>

我Mainifiest文件是

My Mainifiest file is

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lifegoal.eshop"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
         <activity
            android:name="com.lifegoal.eshop.Splash_Screen_Activity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </manifest>

不过,我有错误,如

But I got error like

   04-28 12:53:05.632: E/AndroidRuntime(3181): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifegoal.eshop/com.lifegoal.eshop.Home_Screen_Activity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
   04-28 12:53:05.632: E/AndroidRuntime(3181):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
   04-28 12:53:05.632: E/AndroidRuntime(3181):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)

家伙,我需要帮助乌拉圭回合在..thx提前

Guys I Need ur help ..thx in advance

推荐答案

试着改变你的 style.xml 像下面这为我的作品:

Try changing your style.xml like below It works for me:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->

    </style>

</resources>

据开发商指南,我们必须使用 NoActionBar 主题中使用的工具栏作为一个操作栏。
此外扩展您与 ActionBarActivity 活动。

According to developers guide we have to use NoActionBar theme to use toolbar as a action bar. Also extends your activity with ActionBarActivity.

修改
使用 AppCompatActivity 而不是 ActionBarActivity ,它是pcated德$ P $。

Edit Use AppCompatActivity instead of ActionBarActivity, It is deprecated.

这篇关于材料抽屉在Eclipse ISSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆