Tag: android drawable

Android TextInputLayout图标出错(或提示)文本

我正在使用TextInputLayoutHelper小部件,以遵循浮动标签输入的材料指南。 它目前看起来像这样: 我的代码 在我的onCreatefunction上,我有: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val passwordInputLayout = this.findViewById(R.id.input_layout_password) passwordInputLayout.error = “8+ characters and at least one uppercase letter, a number, and a special character (\$, #, !)” passwordInputLayout.isErrorEnabled = true } 和我的部件在我的xml看起来像… 我想做的事 我想在错误文本右侧的错误/提示文本(惊叹号三角形)中放置一个图标。 我的尝试 尝试1 我发现一个使用setError(text, drawable) 的实现 ,但我使用Kotlin setError不可用。 所以我试了一下: val warningIcon = ResourcesCompat.getDrawable(resources, R.drawable.ic_warning_black_24dp, null) warningIcon?.setBounds(0, […]

一些绘图不能被发现

在我添加了更多的矢量绘图之后,我注意到以前的一些绘图并不工作(大约11)。 与其他人一样,我没有任何问题 – 他们正确地显示。 我将Java类中的每个drawable与image.setImageResource(R.drawable.path_to_image); 而且大多数都没有任何问题。 我只有几个这样的问题。 运行一个应用程序,并试图显示这些drawable我得到这样的错误: Unable to find resource: 2131099763 android.content.res.Resources$NotFoundException: Drawable com.example.example_app:drawable/f_user_achievements_learning1h with resource ID #0x7f060073 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/f_user_achievements_learning1h.xml from drawable resource ID #0x7f060073 at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.getDrawable(Resources.java:767) at android.content.Context.getDrawable(Context.java:525) at android.widget.ImageView.resolveUri(ImageView.java:840) at android.widget.ImageView.onMeasure(ImageView.java:982) at android.view.View.measure(View.java:19734) at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:222) at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117) at android.widget.TableRow.onMeasure(TableRow.java:113) at android.view.View.measure(View.java:19734) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) at […]

如何在图片中添加一个动态文本,全部都是可绘制的,就像Google日历应用中的“今天”操作项一样?

背景 Google日历应用有一个根据当天(“今天”)动态更改的操作项目: 我被要求做一个非常相似的事情,但在文字周围有一个稍微不同的图像。 问题 通过创建一个具有文本和图像的Drawable(基于这里 ),我成功地实现了它的工作。 不过,我觉得我做得不够好: 文字字体在不同设备上可能会有所不同,因此可能不适合我写的内容。 不知道是由于VectorDrawable还是文本,但我认为文字看起来不那么居中。 似乎在左边。 如果我使用两位数字,情况尤其如此: 为了垂直居中,我不认为我做了正确的计算。 我在那里尝试了更多合乎逻辑的事情,但是他们没有集中精力。 我试过了 下面是完整的代码(也可以在这里find一个项目): TextDrawable.java public class TextDrawable extends Drawable { private static final int DEFAULT_COLOR = Color.WHITE; private static final int DRAWABLE_SIZE = 24; private static final int DEFAULT_TEXT_SIZE = 8; private Paint mPaint; private CharSequence mText; private final int mIntrinstSize; private final […]

如何将Drawable转换为位图?

我想设置一个特定的Drawable作为设备的壁纸,但所有壁纸function只接受Bitmap s。 我无法使用WallpaperManager因为我在2.1之前。 此外,我的绘图从网上下载,不居住在R.drawable 。

在xml相同的代码中以编程方式绘制的形状

我有以下的XML: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/coral_seconds"/> <size android:height="24dp" android:width="24dp"/> </shape> 如何使这个XML作为一个programatical Drawable对象? 我尝试没有成功(Kotlin): val circle = ShapeDrawable(OvalShape()) circle.paint.color = ContextCompat.getColor(context, resId) circle.paint.style = Paint.Style.FILL; 答案可以在Java中,我不介意。