我在旧的(pre-L)设备上获得了一个Resources $ notfoundexception.我在下面包含完整的堆栈跟踪.
我的支持库版本是最新版本(24.1.0),我在gradle文件中包含了以下内容:
vectorDrawables.useSupportLibrary = true
Run Code Online (Sandbox Code Playgroud)
我的基本主题是noactionbar主题 - "Theme.AppCompat.Light.NoActionBar"
崩溃发生在我的代码中的这一行,我在支持工具栏中引用后退箭头,以便稍后更改它的颜色:
@SuppressLint("PrivateResource") final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
Run Code Online (Sandbox Code Playgroud)
可能是什么原因造成的?此代码适用于L或以上的所有用户.
07-19 22:36:57.029 9330-9330/mypkg E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {mypkg/mypkg.activites.myActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:1957) …Run Code Online (Sandbox Code Playgroud) android android-resources android-support-library android-toolbar android-vectordrawable
我有一个vector绘画.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#65666a"
android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z" />
</vector>
Run Code Online (Sandbox Code Playgroud)
我添加android:autoMirrored="true"了支持RTL的属性,但它仅用于API 19及更高版本.但我的最低API级别是API 17.如何添加后向可比性?任何帮助,将不胜感激.
我正在使用支持lib版本24.2.1,并启用了支持向量 AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
这些关于支持向量的函数有什么不同?我在用VectorDrawableCompat.create(getResources(), R.drawable.my_vector, null).但是这样在我的测试设备(Android 4.3)上生成一个drawable时,在编程上按钮上设置一个drawable就像这样:
button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
使用AppCompatDrawableManager.get().getDrawable(getActivity(), R.drawable.my_vector);(包装在状态列表选择器中)似乎工作正常,虽然我似乎无法找到它的文档.
我有一个复杂的矢量drawable,我想动画.我使用@ RomanNurik的网络工具从svg创建动画
<animated-vector>根据文件说明,这给了我一个有效的.它是一个"一体化"的XML文件.
xml的drawable分为2组,每组包含2个路径,并且还添加了4个动画,如下所示:
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="56dp"
android:height="56dp"
android:viewportHeight="56.0"
android:viewportWidth="56.0">
<group
android:name="group_1"
android:pivotX="25"
android:pivotY="25">
<path
android:name="path_3_1"
... />
<path
android:name="path"
... />
</group>
<group
android:name="group"
android:pivotX="25"
android:pivotY="25">
<path
android:name="path_1"
... />
<path
android:name="path_2"
... />
</group>
</vector>
</aapt:attr>
<target android:name="path">
<aapt:attr name="android:animation">
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:name="path"
... />
<objectAnimator
android:name="path"
.../>
</set>
</aapt:attr>
</target>
<target android:name="group_1">
<aapt:attr name="android:animation">
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:name="group_1"
... />
<objectAnimator
android:name="group_1"
... /> …Run Code Online (Sandbox Code Playgroud) Android虽然支持SVG,但为什么要转换成VectorDrawable呢?
此代码示例显示了 Android 中的 SVG:
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
imageView.setImageDrawable(svg.createPictureDrawable());
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用了一些矢量drawables但仅适用于v21及更高版本 - 它们位于资源文件夹drawable-anydpi-v21中,并且还具有其他api级别的回退位图版本(drawable-hdpi.mdpi,...).
当我使用此配置运行robolectric时
@Config(sdk = 16, application = MyApp.class, constants = BuildConfig.class, packageName = "com.company.app")
Run Code Online (Sandbox Code Playgroud)
使用这些drawables在视图膨胀时出现以下错误
Caused by: android.content.res.Resources$NotFoundException: File ./app/build/intermediates/data-binding-layout-out/dev/debug/drawable-anydpi-v21/ic_info_outline_white_24dp.xml from drawable resource ID #0x7f02010e
Caused by: org.xmlpull.v1.XmlPullParserException: XML file ./app/build/intermediates/data-binding-layout-out/dev/debug/drawable-anydpi-v21/ic_info_outline_white_24dp.xml line #-1 (sorry, not yet implemented): invalid drawable tag vector
Run Code Online (Sandbox Code Playgroud)
build.gradle的相关部分是:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 79
versionName "0.39"
// Enabling multidex support.
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testApplicationId "com.example.app.test"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
testOptions {
unitTests.returnDefaultValues = …Run Code Online (Sandbox Code Playgroud) 在Google Play开发者控制台中上传APK文件时出现以下错误:
上传失败
您需要检查APK中的图标,因为它无效.
SO我发现的所有答案似乎都暗示你必须将Vector Drawable图标转换为PNG才能摆脱这个错误.
为什么这有必要?Vector Vector Drawables的全部意义是避免手动生成PNG吗?
编辑:
将我的应用图标转换为PNG实际上有所帮助.但我仍然无法理解为什么这是必要的.Android Studio是不是应该在构建时生成PNG?
我正在 Android 上处理 SVG 文件。Android Studio 将 SVG 文件转换为包含矢量和路径元素的 XML 文件。一个 XML 文件可以有多个“路径”元素。问题就从这里开始。我想让每个路径元素能够在不使用 webview 的情况下单独单击。(javascript 的原因是有风险的!)有没有办法做到这一点?
我不能使用点击像素颜色。因为它们变化很大。我可以将每个路径元素分离到不同的 XML 文件。但是这条路径也会记住它们所在的位置。当我想将每个 XML 文件添加到 FrameLayout 中时,它们将矩形边缘扩展到手机边缘。即使他们在 width 和 height 属性中有 wrap_content .. 所以 onClick 事件被阻止。onClick 事件只有一个。您可以检查照片中的蓝色边缘。每个图像视图的蓝色边缘都相同:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/path_one" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/path_two" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/path_three" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
路径一:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="800dp"
android:height="340dp"
android:viewportHeight="340"
android:viewportWidth="800">
<path
android:fillAlpha="1"
android:fillColor="#da241c"
android:pathData="M52.39,44.01L54.63,41.94L57.68,42.54L64.66,41.57L66.41,42.87L67.51,45.88L72.34,49.65L75.51,48.5L78.38,45.54L80.04,39.15L82.2,37.29L88.55,34.96L92.09,34.57L100.5,29.58L100.87,28.25L102.52,28.39L102.52,28.39L103.01,29L103.01,29L99.86,44.65L97.47,48.72L97.49,51.15L95.74,54.66L95.58,57.53L96.47,59.49L96.47,59.49L94.92,62.8L91.57,62.71L86.49,60.02L76.48,62.25L74.69,65.68L74.09,69.27L69.49,73.59L67.58,77.44L62.61,81.12L57.04,82.69L54.94,84.99L52.22,85.67L52.22,85.67L52.17,82.72L55.49,74.92L52.38,73.87L46.42,74.15L46.42,74.15L42.46,68.99L43.56,60.73L41.5,58.83L42.36,57.78L46.69,57.12L50.78,53.06L53.17,48.89z"
android:strokeAlpha="1"
android:strokeColor="#FFFFFF"
android:strokeWidth="0.5" />
</vector>
Run Code Online (Sandbox Code Playgroud)
路径二:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="800dp"
android:height="340dp" …Run Code Online (Sandbox Code Playgroud) 我需要更改 MaterialButton 的图标色调,该图标是一个 xml 矢量资产,我可以在 xml 布局中轻松更改色调,但是我需要通过单击以编程方式更改颜色,我无法找到与此问题相关的内容,这是我的按钮:
<com.google.android.material.button.MaterialButton
android:id="@+id/btnShowDepartmentList"
style="@style/com.madison.Button.IconButton"
app:iconSize="32dp"
android:padding="0dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
app:icon="@drawable/ic_list_thumbnails"
android:layout_width="42dp"
android:layout_height="42dp"
app:iconTint="@color/orangeLighter"
tools:ignore="RtlSymmetry"/> ```
Run Code Online (Sandbox Code Playgroud) 我有来自 iOS 项目的 PDF 图像资产,我需要将其添加到 Android Studio 项目中。是否可以将 PDF 添加到 Android Studio,或者我是否必须使用 Gimp 或 Illustrator 等外部转换器将资产转换为 SVG/PSD/XML?(谷歌的Android矢量图形文档)如果是这样,这样做的最佳实践是什么?我问是因为,到目前为止,我尝试这样做的结果是低质量的资产。
pdf android vector-graphics android-studio android-vectordrawable