gpt4 book ai didi

android - 使用矢量可绘制色调颜色选择器在膨胀 View 期间崩溃

转载 作者:太空狗 更新时间:2023-10-29 13:57:00 28 4
gpt4 key购买 nike

我想使用带有色调颜色选择器的矢量绘图

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_ef" android:state_enabled="false"/>
<item android:color="@color/gray_ef" android:state_pressed="true"/>
<item android:color="@color/app_main_blue"/>
</selector>

样式声明:

 <style name="SocialButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:background">@drawable/into_social_bg</item>
<item name="android:tint">@color/intro_social_tiny</item>
<item name="android:clickable">true</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_marginRight">1dp</item>
</style>

和布局xml中的声明

<ImageView
android:id="@+id/tw_ImageView_AddSocialFragment"
style="@style/SocialButton"
app:srcCompat="@drawable/v_soc_tw"/>

它在 API 21+ 的设备上运行良好,但在较低的设备上我有一个错误:

android.view.InflateException: Binary XML file line #15: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.cs.liker.ui.intro.AddSocialFragment.onCreateView(AddSocialFragment.java:56)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:164)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:608)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570)
at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:1019)
at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2978)
at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:279)
at com.cs.liker.ui.intro.IntroActivity.checkViewPagerCount(IntroActivity.java:79)
at com.cs.liker.ui.intro.IntroActivity.moveNextScreen(IntroActivity.java:66)
at com.cs.liker.ui.intro.LicenseFragment.click(LicenseFragment.java:34)
at com.cs.liker.ui.intro.LicenseFragment$$ViewBinder$1.doClick(LicenseFragment$$ViewBinder.java:17)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:4463)
at android.view.View$PerformClick.run(View.java:18770)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
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:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: "res/color/intro_social_tiny.xml"
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
at android.content.res.TypedArray.getInt(TypedArray.java:255)
at android.widget.ImageView.<init>(ImageView.java:155)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at com.cs.liker.ui.intro.AddSocialFragment.onCreateView(AddSocialFragment.java:56) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) 
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) 
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570) 
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:164) 
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177) 
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:608) 
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570) 
at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:1019) 
at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2978) 
at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:279) 
at com.cs.liker.ui.intro.IntroActivity.checkViewPagerCount(IntroActivity.java:79) 
at com.cs.liker.ui.intro.IntroActivity.moveNextScreen(IntroActivity.java:66) 
at com.cs.liker.ui.intro.LicenseFragment.click(LicenseFragment.java:34) 
at com.cs.liker.ui.intro.LicenseFragment$$ViewBinder$1.doClick(LicenseFragment$$ViewBinder.java:17) 
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) 
at android.view.View.performClick(View.java:4463) 
at android.view.View$PerformClick.run(View.java:18770) 
at android.os.Handler.handleCallback(Handler.java:808) 
at android.os.Handler.dispatchMessage(Handler.java:103) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5333) 
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:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 

我是矢量绘图的新手,有人可以给我建议来解决这个问题吗?

最佳答案

布局

<android.support.v7.widget.AppCompatImageView
android:id="@+id/tw_ImageView_AddSocialFragment"
style="@style/SocialButton"
app:srcCompat="@drawable/v_soc_tw" />

风格

<style name="SocialButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:background">@drawable/into_social_bg</item>
<item name="android:clickable">true</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_marginRight">1dp</item>
</style>

颜色

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_ef" android:state_enabled="false"/>
<item android:color="@color/gray_ef" android:state_pressed="true"/>
<item android:color="@color/app_main_blue"/>
</selector>

矢量

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="@color/intro_social_tiny">
<path
android:fillColor="#616161"
android:pathData="M17,12h-5v5h5v-5zM16,1v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2h-1L18,1h-2zM19,19L5,19L5,8h14v11z"/>
</vector>

from the official docs of VectorDrawable

android:tint The color to apply to the drawable as a tint. By default, no tint is applied.

关于android - 使用矢量可绘制色调颜色选择器在膨胀 View 期间崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673196/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com