선택기에서 모양을 설정하고 기타-모두 괜찮습니다. 내가 변경하면 <vector>
-앱이 충돌합니다. ImageViev app : srcCompat = "@ drawable / icon으로 설정할 수 있지만 모두 괜찮지 만 RadioButton app : srcCompat ="@ drawable / icon_selecton으로 설정하고 항목에 사용하면
`<item android:drawable="@drawable/icon_active" android:state_checked="true"/>
<item android:drawable="@drawable/icon" android:state_checked="false"/>`
API19에 대한 오류를 보았지만 API21에서는 모두 괜찮습니다!
충돌 코드 :
`Android.Views.InflateException: Binary XML file line #1:
Error inflating class android.widget.ToggleButton`
23.4.0.1 라이브러리를 사용합니다.
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에는 다른 색상 만 있음)
<?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>
그리고 지원 라이브러리 :
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
새 앱 을 만들고이 오류를 재현 하고 App1.sln 아카이브에 연결합니다.
이것은 Android 5.1에서 완벽하게 작동하지만 4.4에서는 충돌했습니다. 드로어 블 항목-벡터에서 제거하면 4.4에서 작동하지만 아이콘이없는 모양입니다.
활동을 AppCompatActivity에서 파생시키고 정적 생성자를 추가하십시오.
[Activity (Label = "App1.Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : AppCompatActivity
{
static MainActivity()
{
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
}
protected override void OnCreate (Bundle bundle)
{
AppCompat에서 파생 된 매니페스트의 테마를 변경해야합니다. 다른 테마를 선택할 수 있습니다 (I like Dark)
<application android:label="App1.Droid" android:theme="@style/Theme.AppCompat"></application>
선택기에서 드로어 블을 사용하여 항목을 벡터로 대체합니다.
<?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은 이전에 벡터처럼 보입니다.
<?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>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다