gpt4 book ai didi

android - Eclipse Isse 中的 Material 抽屉

转载 作者:行者123 更新时间:2023-11-29 15:51:18 28 4
gpt4 key购买 nike

我想在 Android 应用程序中添加 Material 抽屉...所以我们需要包含一个工具栏...但是当我们包含工具栏时我得到了错误我的 activitymain_xml 代码是

       <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>

工具栏的代码是

    <?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"/>

包含工具栏的代码是

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

我的Style.xml是

    <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>

我最主要的文件是

 <?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>

但是我得到了这样的错误

   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)

伙计们,我需要你的帮助..提前谢谢

最佳答案

尝试像下面这样更改您的 style.xml 它对我有用:

<resources>

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

</style>

</resources>

根据开发人员指南,我们必须使用 NoActionBar 主题才能将工具栏用作操作栏。还使用 ActionBarActivity扩展您的 Activity 。

编辑使用 AppCompatActivity 而不是 ActionBarActivity,它已被弃用。

关于android - Eclipse Isse 中的 Material 抽屉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29912781/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com