android.support.v7.internal.widget.ActionBarOverlayLayout无法实例化
我第一次安装了(Android Studio 1.2 + SDK包),我创build了一个带有演示选项卡活动的testing项目。 我没有写一行代码,一切都是由Android Studio生成的
在fragment_main.xml中发生以下问题。
java.lang.ClassNotFoundException: android.support.v4.view.ViewPropertyAnimatorListener at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:127) at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:53) at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:84) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585) at java.lang.Class.getConstructor0(Class.java:2885) at java.lang.Class.getConstructor(Class.java:1723) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:348) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105) at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:177) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:214) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:142) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at com.android.layoutlib.bridge.bars.BridgeActionBar.<init>(BridgeActionBar.java:84) at com.android.layoutlib.bridge.bars.AppCompatActionBar.<init>(AppCompatActionBar.java:56) at com.android.layoutlib.bridge.impl.RenderSessionImpl.createActionBar(RenderSessionImpl.java:1691) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:362) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:497) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:485) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:485) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:590) at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at 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:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity$PlaceholderFragment"> <TextView android:id="@+id/section_label" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
活动(在这里没有代码错误,但我很惊讶地看到在演示代码中不build议使用的函数的调用):
import java.util.Locale; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentPagerAdapter; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class MainActivity extends ActionBarActivity implements ActionBar.TabListener { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link FragmentPagerAdapter} derivative, which will keep every * loaded fragment in memory. If this becomes too memory intensive, it * may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ SectionsPagerAdapter mSectionsPagerAdapter; /** * The {@link ViewPager} that will host the section contents. */ ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab( actionBar.newTab() .setText(mSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } } @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); } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, switch to the corresponding page in // the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a PlaceholderFragment (defined as a static inner class below). return PlaceholderFragment.newInstance(position + 1); } @Override public int getCount() { // Show 3 total pages. return 3; } @Override public CharSequence getPageTitle(int position) { Locale l = Locale.getDefault(); switch (position) { case 0: return getString(R.string.title_section1).toUpperCase(l); case 1: return getString(R.string.title_section2).toUpperCase(l); case 2: return getString(R.string.title_section3).toUpperCase(l); } return null; } } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { /** * The fragment argument representing the section number for this * fragment. */ private static final String ARG_SECTION_NUMBER = "section_number"; /** * Returns a new instance of this fragment for the given section * number. */ public static PlaceholderFragment newInstance(int sectionNumber) { PlaceholderFragment fragment = new PlaceholderFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; } public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } }
有完全相同的问题。 我通过改变res/values/styles.xml
来摆脱它
<!-- Base application theme. --> <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </style>
Android Tools Project网站列出了Android Gradle插件1.2版本的一个已知bug,声明它将会被版本1.2.3
请参阅: http : //tools.android.com/knownissues
他们提出了3个解决方法:
引用上面的链接:
解决方法1:首先手动构build项目,然后手动同步项目(使用工具栏中的同步与Gradle文件,或从工具> Android菜单),然后最后按布局编辑器上方工具栏中的刷新。
解决方法2:现在将Android Gradle插件从1.2.x切换到1.1.3。 1.2.3发布时,可以切换回1.2.x版本。
解决方法3:如果上述解决方法不适用于您,并且您在Windows上,请尝试从[网站链接]下载构build版本
我有同样的问题,我认为这是一个问题,同时渲染AppCompatTheme。
使预览再次切换到股票主题,如“材料光”/“Material.Light.DarkActionBarTheme”
我有同样的错误。 解决scheme是:
- 首先你必须同步你的项目。
- 接下来,转到生成菜单,并在清洁项目上点击。
- 最后,再次,去生成菜单,并在重build选项clic。
没有必要改变一个东西,像一个魅力。
我有一个由Android Studio 1.2创build的绝对新项目的错误。
@ florent的解决scheme为我工作:
切换到“材质光”/“Material.Light.DarkActionBarTheme”
改变了这一点,build立了项目,渲染开始工作。
我在我的styles.xml中使用了<style name="AppTheme" parent="android:Theme.Light">
,它工作。
我通过改变下面的值来解决它:Relative Layout – > Properties – > Padding | 以数字值而不是默认值。 然后点击重build。
对我来说,修复是使用最新的gradle版本
我面临同样的问题。 这是AppCompat主题的一些渲染问题。 所以我修改了styles.xml文件,如下所示:所以问题解决了。但是如果我们仍然想使用AppCompat主题,应该怎么做,我还没有find。