android中的SVG/VectorDrawable问题
我在Android项目中使用了svg文件。Android 4.4或更低版本中存在问题。我在gradle文件和AppCompatDelegate.setCompatorFromResourcesEnabled(true)中尝试了这些解决方案在除gridview之外的android中的SVG/VectorDrawable问题,android,svg,android-5.0-lollipop,android-support-library,android-vectordrawable,Android,Svg,Android 5.0 Lollipop,Android Support Library,Android Vectordrawable,我在Android项目中使用了svg文件。Android 4.4或更低版本中存在问题。我在gradle文件和AppCompatDelegate.setCompatorFromResourcesEnabled(true)中尝试了这些解决方案在除gridview之外的BaseActivity的静态块中,图像不会显示在应用程序中 不使用上述3种解决方案,只需将您的ImageView替换为android.support.v7.widget.AppCompatImageView。不需要做任何额外的努力。
BaseActivity
的静态块中,图像不会显示在应用程序中 不使用上述3种解决方案,只需将您的ImageView
替换为android.support.v7.widget.AppCompatImageView
。不需要做任何额外的努力。
注意:-不支持使用drawableRight和drawableLeft的文本视图
、编辑文本
和其他类。对于它们,在FrameLayout
或RelativeLayout
中使用TextView或EditText
和AppCompatImageView
创建自己的复合视图类。EditText
内部的drawableRight
示例:-
布局文件
attrs.xml文件
将SVG
文件转换为XML
,并从Drawable
文件夹中使用它。选中。Android Studio具有此功能。右键单击drawable
文件夹->选择“新建”->选择“矢量资源”并选择svg文件。它将被转换成可矢量绘制的xml文件。目的是我们也可以以同样的方式使用SVG文件,因为xml在所有android版本中都可以正常工作。您的“问题”是什么?如果不知道出了什么问题,就很难帮助您。@PaulLeBeau检查最后一行,除了gridview,应用程序中不会显示图像。不要浪费时间在Android上使用SVG。我向你保证,无论你从设计师那里得到什么样的SVG,你都无法直接使用它们,因为Android不支持很多SVG功能。因此,paintcodeapp.com的流行程度我刚刚查看了www.paintcodeapp.com,在我们的客户下显示了谷歌!!这证实了Android中的SVG处理非常糟糕!
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edt_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:paddingEnd="40dp"
android:paddingLeft="5dp"
android:paddingRight="40dp"
android:paddingStart="5dp" />
<android.support.v7.widget.AppCompatImageView
android:id="@+id/search"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right|center_vertical"
android:layout_margin="8dp"
android:src="@drawable/ic_svg_search" />
</FrameLayout>
public class EditTextWithDrawable extends FrameLayout {
public AppCompatImageView mDrawableRight;
public EditText mAppEditText;
public AppEditTextWithDrawable(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
private void init(AttributeSet attrs) {
if (attrs != null && !isInEditMode()) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.compound_view, this, true);
mDrawableRight = (AppCompatImageView) ((FrameLayout) getChildAt(0)).getChildAt(1);
mAppEditText = (EditText) ((FrameLayout) getChildAt(0)).getChildAt(0);
TypedArray attributeArray = getContext().obtainStyledAttributes(
attrs,
R.styleable.EditTextWithDrawable);
int drawableRes =
attributeArray.getResourceId(
R.styleable.EditTextWithDrawable_drawableRightSVG, -1);
if (drawableRes != -1) {
mDrawableRight.setImageResource(drawableRes);
}
attributeArray.recycle();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AppEditTextWithDrawable">
<attr name="drawableRightSVG" format="reference" />
</declare-styleable>
</resources>