2016-10-25 4 views
1

In Selektor versuche ich Form, andere - alles in Ordnung. Wenn ich zu <vector> wechseln - App ist abgestürzt. kann ich ImageViev app gesetzt: srcCompat = „@ ziehbar/Symbol und alle in Ordnung, aber wenn ich auf RadioButton- app gesetzt: srcCompat =“ @ ziehbar/icon_selecton und Verwendung für ArtikelAppCompat Vector Drawable abgestürzt auf RadioButton Selektor

`<item android:drawable="@drawable/icon_active" android:state_checked="true"/> 
<item android:drawable="@drawable/icon" android:state_checked="false"/>` 

ich diesen Fehler gesehen für API19, aber auf API21 alles in Ordnung!

Crash-Code:

`Android.Views.InflateException: Binary XML file line #1: 
Error inflating class android.widget.ToggleButton` 

Ich benutze 23.4.0.1 Bibliothek.

Main.axml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:background="@drawable/a2" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:windowNoTitle="true" 
    android:id="@+id/container"> 
<RadioGroup 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/radioGroup1" 
    android:orientation="horizontal" 
    android:gravity="center"> 
    <RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/man" 
    android:button="@drawable/woman_selector" 
    android:radius="50dp" 
    android:layout_marginRight="40dp" /> 
    <RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/woman" 
    android:button="@drawable/man_selector" 
    android:radius="50dp" 
    android:layout_marginLeft="40dp" /> 
</RadioGroup> 
</LinearLayout> 

woman_selextor.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/selwoman" android:state_checked="true"/> 
<item android:drawable="@drawable/defwoman" android:state_checked="false"/> 
</selector> 

defwoman.xml (selwoman.xml nur diffirence Farben)

<?xml version="1.0" encoding="UTF-8" ?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" 
       android:id="@+id/shapeBg"> 
      <solid android:color="#B733C6"/>  
      <size android:width="70dp" android:height="70dp"/> 
     </shape> 
    </item> 
    <item> 
    <vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="70dp" 
    android:height="70dp" 
    android:viewportWidth="70" 
    android:viewportHeight="70"> 
    <path 
     android:fillColor="#ffffff" 
     android:pathData="M43 45l-6 0 0 -5c6,-1 11,-6 11,-13 0,-7 -6,-13 -13,-13 -7,0 -13,6 -13,13 0,7 
5,12 11,13l0 5 -6 0c-2,0 -2,3 0,3l6 0 0 6c0,2 4,2 4,0l0 -6 6 0c2,0 2,-3 
0,-3zm-18 -18c0,-5 5,-10 10,-10 5,0 10,5 10,10 0,5 -5,10 -10,10 -5,0 -10,-5 
-10,-10z" /> 
</vector> 
    </item> 
</layer-list> 

Und Support-Bibliothek:

Xamarin.Android.Support.Animated.Vector.Drawable.23.4.0.1 Xamarin.Android.Support.v4.23.4.0.1 Xamarin.Android.Support.v7.AppCompat. 23.4.0.1 Xamarin.Android.Support.Vector.Drawable.23.4.0.1

ich neue App erstellen und diesen Fehler reproduzieren, link to App1.sln archive

Diese perfekte Funktion auf Android 5.1 aber abgestürzt auf 4.4. Wenn Sie aus einem drawbaren Element - Vektor entfernen, arbeiten Sie mit der Form 4.4, aber ohne Symbol.

+0

können Sie Stellen Sie komplette axml zur Verfügung, wo Radioknöpfe benutzt werden, also können wir dieses schnell reproduzieren? –

+0

@ YuriS, ich bin Code zu meiner Frage hinzufügen, Haupt, Selektor und Vektor ziehbar. – Ron

+0

Die Bereitstellung von Link zu dem Projekt war die große Hilfe. Konnte Problem schnell reproduzieren –

Antwort

0

Machen Sie Ihre Aktivität von AppCompatActivity ableiten und fügen Sie statischen Konstruktor

[Activity (Label = "App1.Droid", MainLauncher = true, Icon = "@drawable/icon")] 
     public class MainActivity : AppCompatActivity 
     { 

      static MainActivity() 
      { 
       AppCompatDelegate.CompatVectorFromResourcesEnabled = true; 
      } 

      protected override void OnCreate (Bundle bundle) 
      { 

Sie das Thema im Manifest von AppCompat abgeleitet haben zu ändern. Sie können verschiedene Themen auswählen (I Dunkle mag)

<application android:label="App1.Droid" android:theme="@style/Theme.AppCompat"></application> 

In Selektoren Ersatzartikel mit Vektor durch Artikel mit ziehbar

<?xml version="1.0" encoding="UTF-8" ?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" 
      android:id="@+id/shapeBg"> 
     <solid android:color="#fff"/> 
     <size android:width="70dp" android:height="70dp"/> 
    </shape> 
    </item> 
    <item android:drawable="@drawable/woman_path"/> 
</layer-list> 

woman_path.xml sieht aus wie Ihre Vektor vor

<?xml version="1.0" encoding="UTF-8" ?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="70dp" 
    android:height="70dp" 
    android:viewportWidth="70" 
    android:viewportHeight="70"> 
    <path 
     android:fillColor="#ffffff" 
     android:pathData="M43 45l-6 0 0 -5c6,-1 11,-6 11,-13 0,-7 -6,-13 -13,-13 -7,0 -13,6 -13,13 0,7 
5,12 11,13l0 5 -6 0c-2,0 -2,3 0,3l6 0 0 6c0,2 4,2 4,0l0 -6 6 0c2,0 2,-3 
0,-3zm-18 -18c0,-5 5,-10 10,-10 5,0 10,5 10,10 0,5 -5,10 -10,10 -5,0 -10,-5 
-10,-10z" /> 
</vector> 
+0

Danke! Hat funktioniert! 'static MainActivity()' – Ron