Hello Everyone
在这种情况下,有很多线程可以使用...我尝试了一切,但没有运气。 我刚接触到android background.Iam c#guy,现在iam与xamarin droid一起工作......所以任何人都可以解释什么是错误。这个解决方案不能正常工作** PRE lolipop devices **。
我的布局
<?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"
android:id="@+id/quickreturn_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/masonry_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
我使用的是appcompact主题
值/ Style.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="Theme.Splash"
parent="@android:style/Theme.Holo.Light">
<item name="android:windowBackground">@drawable/splashscreen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="AppTheme" parent="Base.Theme">
</style>
<style name="Base.Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/DarkOrangeLight</item>
<item name="colorPrimaryDark">@color/DarkOrange</item>
<item name="colorAccent">@color/DarkOrangeAcent</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowBackground">@color/bg</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowNoTitle">true</item>
<!-- Customize your theme here. -->
</style>
</resources>
值-21 \ styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Base.Theme">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/DarkOrange</item>
</style>
</resources>
我的 主要活动
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
try
{
SetContentView(Resource.Layout.MansoryLayout);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
我在setcontentview方法上遇到错误一次调用....
详细例外情况:
{Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.App.Activity.SetContentView (Int32 layoutResID) [0x00070] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/platforms/android-22/src/generated/Android.App.Activity.cs:5500
at test.Droid.Activity.MoviesActivity+<OnCreate>d__16.MoveNext () [0x00041] in E:\project\test\test\test\test.Droid\Activity\MoviesActivity.cs:92
--- End of managed exception stack trace ---
android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.AppBarLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at md57bfe09fe2721efc565bcf4b957f437a7.MoviesActivity.n_onCreate(Native Method)
at md57bfe09fe2721efc565bcf4b957f437a7.MoviesActivity.onCreate(MoviesActivity.java:46)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5095)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 23 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b00d9 a=2 r=0x7f0b00d9}
at android.content.res.Resources.loadDrawable(Resources.java:2068)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.support.design.widget.AppBarLayout.<init>(AppBarLayout.java:139)
我在我的解决方案中添加了包
我已附加错误消息的屏幕截图
答案 0 :(得分:7)
您可能会延长Activity
而不是AppCompatActivity
。
此外,您的主题需要一个合适的父母。
<style name="AppTheme" parent="Theme.AppCompat">
另外请确保您有此电话:
protected override void OnCreate(Bundle bundle)
{
SetTheme(Resource.Style.AppTheme);
base.OnCreate(bundle)
这解决了我的问题。
答案 1 :(得分:3)
补充Demian,你也可以使用注释
[Activity(Theme ="@style/AppTheme")]
public class MainActivity : AppCompatActivity {
....
}
答案 2 :(得分:0)
我遇到了同样的问题。它发生在从23.1.1.1更新所有支持库到版本23.4.0.1之后。我通过降级这些库来解决它。