Tag: 可绘制的

使用Android在xml中使用ShapeDrawable绘制多个形状

我正在代码中的自定义视图中画一个canvas上的圈数。 圆是静态的,不会改变。 我想用xml中的ShapeDrawable来绘制它们来帮助清理我的代码。 我将有许多不同的drawable,用户可以select,因此我不想在代码中这样做。 有3或4 xml drawables似乎很整洁我。 我已经使用ShapeDrawable在xml中创build了一个圆,但无法向xml添加多个形状。 如何使用ShapeDrawable将多个graphics添加到xml文档中。

DrawableCompat着色在前棒棒糖上不起作用

我正在使用新的TextInputLayout来包装一个EditText。 当我确定一个字段有错误时,我执行以下操作: Drawable drawable = DrawableCompat.wrap(getEditText().getBackground()); DrawableCompat.setTintList(drawable, ColorStateList.valueOf(Color.RED)); 这适用于5.0,并将下划线变成红色,但在4.4或4.1testing设备上不做任何事情。 我在这里错过了什么? 似乎很简单,根据谷歌“只是作品”…非常确定,我也有最新版本: 编译'com.android.support:design:22.2.0' FWIW,如果我做setColorFilter而不是setTint,那么它适用于所有的平台,但我有它的问题离开,并没有回来,只要焦点设置/左/等…我宁愿这样做色调(如果有人正在寻找额外的信贷,真的更喜欢把色彩应用于焦点和非焦点状态) 谢谢!

可绘制的形状作为背景,底部有一条线

我使用drawable作为TextView的背景,只是在文本下面有一个分隔线。 用这个drawable-xml来描述它: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <solid android:color="#FFDDDDDD" /> <gradient android:angle="0" android:startColor="#FFAAAAAA" android:endColor="#FFEEEEEE" /> </shape> </item> <item android:bottom="2dp"> <shape android:shape="rectangle"> <solid android:color="#FF000000" /> </shape> </item> </layer-list> 但是这种方法在黑色矩形上方绘制了一个彩色矩形。 我想只有在形状的底部没有黑色矩形的线,因为黑色不透明。 我怎么能做到这一点?

只有在Android应用程序中使用XHDPI drawables?

如果您计划在不久的将来支持LDPI,MDPI,HPDI和XHDPI,可以在项目中只包含XHDPI drawable,并让这些设备按照他们想要的分辨率进行缩放? 我已经testing过在Photoshop中将drawables调整为MDPI和HDPI,然后将结果与XHDPI drawables进行比较,只调整Android的大小,我看不出任何区别。 采取这种捷径是不好的devise? 不必将每个drawable调整为3种不同的分辨率就好了。 规划使用目标SDK是2.1或2.2。 BR Emil

可绘制到byte

我有一个ImageView中的ImageView 。 这是非常小的(图标),我想存储在我的SQLite数据库。 我可以从mImageView.getDrawable()获取一个Drawable ,但是我不知道下一步该怎么做。 我不完全理解Android中的Drawable类。 我知道我可以从一个Bitmap获取一个字节数组,如: Bitmap defaultIcon = BitmapFactory.decodeStream(in); ByteArrayOutputStream stream = new ByteArrayOutputStream(); defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] bitmapdata = stream.toByteArray(); 但是,如何从Drawable获取一个字节数组?

如何在Android中find轮廓

如何通过可绘制的Android形状在Android中实现圆形,如下所示:

平铺drawable有时延伸

我有一个ListView的项目有平铺背景。 要做到这一点,我使用以下可绘制的XML: <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/tile" android:tileMode="repeat" /> 通常,这是有效的。 然而,有时候,src drawable不是平铺的,而是延伸到填充整个列表项的。 (我有几个不同的瓷砖,我把它们混合在一个ListView中,如果有拉伸而不是平铺的话,那么它就不会一次完成,因为这是值得的。 我也尝试将android:dither="true"到该xml中,因为我在某处阅读,没有它可能会有错误。 这并没有改变任何东西。 有没有人有同样的问题? 你怎么修好它的?

错误:无法find符号variablesabc_ic_ab_back_mtrl_am_alpha

我添加了片段到我的Android Studio项目使用New > Fragment > Fragment (Blank) 。 因此,当我尝试运行时,项目将无法编译,因为它无法parsingR.drawable.abc_ic_ab_back_mtrl_am_alpha toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); 任何想法如何解决这个问题? 它看起来像我也失去了访问android:buttonTint

联系泡泡EditText

我正在尝试在MultiAutoCompleteTextView创buildMultiAutoCompleteTextView Google+应用中的联系人泡泡。 以下是一个屏幕截图: 。 我试图扩展DynamicDrawableSpan类以便在一段文本的背景中获得一个可展开的绘图 public class BubbleSpan extends DynamicDrawableSpan { private Context c; public BubbleSpan(Context context) { super(); c = context; } @Override public Drawable getDrawable() { Resources res = c.getResources(); Drawable d = res.getDrawable(R.drawable.oval); d.setBounds(0, 0, 100, 20); return d; } } 我的oval.xml可绘制的定义如下: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#352765"/> <padding android:left="7dp" […]

Android – 仅在顶部绘制圆angular

我有这个drawable有一个圆angular的矩形作为背景: <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white" /> <stroke android:width="1dp" android:color="@color/light_gray" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> <corners android:radius="6dp" /> </shape> 如预期的那样,这工作正常。 现在,我想改变这只是围绕顶部的angular落,所以我改变它: <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white" /> <stroke android:width="1dp" android:color="@color/light_gray" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> <corners android:topLeftRadius="6dp" android:topRightRadius="6dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/> </shape> 但是现在没有一个angular落是圆的,我得到一个普通的矩形。 我在这里错过了什么?