更改主题时呈现问题

时间:2015-10-26 12:28:32

标签: android rendering android-theme

我是Appdevelopment的新手,并尝试在Windows 10 x64上更改Android Studio 1.4.1(最新)中的应用主题,但我总是得到例外,这就是我所做的:(是的,我现在已经有很多问题,但我找不到答案)

  1. 启动项目(名称:TEST)
  2. 适用于手机和平板电脑(分钟SDK:API 15 Android 4.0.3 IceCreamSandwich)
  3. 选择空白活动(名称:MainActivity)
  4. 转到activity_main.xml - >设计视图
  5. 选择Nexus 4; API 23; Holo Light / Holo Dark / Material Light / Material Dark ; (API和电话并不重要=>尝试了很多)
  6. 例外:
  7. 渲染问题

    无法实例化以下类:

    • android.support.design.widget.CoordinatorLayout
    • android.support.design.widget.AppBarLayout

    提示:[...]

    例外详细信息

      

    java.lang.IllegalArgumentException:您需要将Theme.AppCompat主题(或后代)与设计库一起使用。       在android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)       在android.support.design.widget.CoordinatorLayout。(CoordinatorLayout.java:178)       在android.support.design.widget.CoordinatorLayout。(CoordinatorLayout.java:172)       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)       at java.lang.reflect.Constructor.newInstance(Constructor.java:422)       在org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:458)       在org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:170)       在org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:103)       在com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:190)       在android.view.BridgeInflater.loadCustomView(BridgeInflater.java:218)       在android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:145)       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)       在android.view.LayoutInflater.inflate(LayoutInflater.java:492)       在android.view.LayoutInflater.inflate(LayoutInflater.java:394)       在com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223)       在com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)       在com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)       在com.android.tools.idea.rendering.RenderTask $ 2.compute(RenderTask.java:510)       在com.android.tools.idea.rendering.RenderTask $ 2.compute(RenderTask.java:498)       在com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)       在com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)       在com.android.tools.idea.rendering.RenderTask.access $ 600(RenderTask.java:72)       在com.android.tools.idea.rendering.RenderTask $ 3.call(RenderTask.java:610)       在com.android.tools.idea.rendering.RenderTask $ 3.call(RenderTask.java:607)       在com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:366)       在com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)       在com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)       在com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel $ 6.run(AndroidDesignerEditorPanel.java:480)       在com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)       在com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)       在com.intellij.util.ui.update.MergingUpdateQueue $ 2.run(MergingUpdateQueue.java:254)       在com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)       在com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)       在com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)       在com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)       at com.intellij.util.Alarm $ Request $ 1.run(Alarm.java:351)       at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)       at java.util.concurrent.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)

    AndroidManifest.xml:(PREMADE)

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="de.minding.test" >
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    

    MainActivity.java:(PREMADE)

    package de.minding.test;
    
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.view.Menu;
    import android.view.MenuItem;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            });
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
    
            return super.onOptionsItemSelected(item);
        }
    }
    

    activity_main.xml:(PREMADE)

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:fitsSystemWindows="true"
        tools:context=".MainActivity">
    
        <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
            android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
    
            <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
                android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
    
        </android.support.design.widget.AppBarLayout>
    
        <include layout="@layout/content_main" />
    
        <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
            android:src="@android:drawable/ic_dialog_email" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    有什么问题?我使用预制的东西,它不起作用? -_-不酷。

    请帮忙! -Minding

2 个答案:

答案 0 :(得分:3)

尝试为项目选择更高的最低SDK(Lollipop或Marshmallow)

如果您确实需要较旧的最低版本,请尝试使用空活动或根本没有活动创建项目,然后从那里开始。

答案 1 :(得分:0)

尝试替换

android:theme="@style/AppTheme.AppBarOverlay"

android:theme="@style/Theme.AppCompat.Light"

CoordinatorLayout