drawable

android drawable

旧街凉风 提交于 2020-11-09 11:30:08
绘制资源类型 (Drawable)类中有个setLevel()的方法他的作用是选择某个级别中可绘制的资源 有时候,我们为了在一个image view中显示不同的图片,往往会使用: if (条件1) { image.setBackground(R.id.xxx1); } else if (条件2) { image.setBackground(R.id.xxx2); } ... 可以使用setLevel()更好的实现 在xml中: <?xml version="1.0" encoding="utf-8"?> <level-listxmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/status_off" android:maxLevel="0"/> <item android:drawable="@drawable/status_on" android:maxLevel="1"/> </level-list> 调用setLevel显示不同的图片 在java中: leftPoint.getDrawable().setLevel(1); viewPager.setOnPageChangeListener(new ViewPager

Dynamically Tint drawable in adapter change color for all

試著忘記壹切 提交于 2020-08-11 03:06:05
问题 I get an array of strings from my server using a volley connection. Every single string contain a different color in hex. I use this color to set Tint of a drawable in adapter. Here my code in adapter: @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { // Get item from position MyObject object = array_data.get(position); ... ... Drawable unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_beenhere_black_24dp); Drawable

Dynamically Tint drawable in adapter change color for all

浪子不回头ぞ 提交于 2020-08-11 03:05:20
问题 I get an array of strings from my server using a volley connection. Every single string contain a different color in hex. I use this color to set Tint of a drawable in adapter. Here my code in adapter: @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { // Get item from position MyObject object = array_data.get(position); ... ... Drawable unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_beenhere_black_24dp); Drawable

Android mirror vector drawable

╄→гoц情女王★ 提交于 2020-08-06 11:41:28
问题 I use a material icon (ic_play_arrow_black_24dp), imported it with the vector studio. Now I want the arrow to point in the other direction as well, without creating a second vector. Is this possible in xml and how? I use the drawable in two Floating Action Button, one for next the other for previous. Edit here is the fab button's XML. I tried already rotation and scale, but it didn´t work <android.support.design.widget.FloatingActionButton android:id="@+id/previous" android:layout_width="wrap

Android mirror vector drawable

安稳与你 提交于 2020-08-06 11:39:29
问题 I use a material icon (ic_play_arrow_black_24dp), imported it with the vector studio. Now I want the arrow to point in the other direction as well, without creating a second vector. Is this possible in xml and how? I use the drawable in two Floating Action Button, one for next the other for previous. Edit here is the fab button's XML. I tried already rotation and scale, but it didn´t work <android.support.design.widget.FloatingActionButton android:id="@+id/previous" android:layout_width="wrap

Can we add text to a drawable?

我只是一个虾纸丫 提交于 2020-08-06 08:41:12
问题 I want to create a drawable which looks like this. and I know how to create the image background but even after searching, I am unable to find how to give text to that drawable file. Is there any way that the drawable file is exactly same containing the text as well? I cant use textview because its a tab and I need drawables to set as background resource (thats what I know, please correct me if I am wrong.). So I want a drawable file which I can set as background. 回答1: Yes you can do that.

How to get color of a button with ripple drawable

做~自己de王妃 提交于 2020-08-06 04:32:05
问题 I have variety of buttons and I would like to get their background color, getting background color in a color drawable is easy but it is not easy in ripple drawable, how can I manage to get background color from ripple drawable. 回答1: Try this: RippleDrawable rippleDrawable = (RippleDrawable) button.getBackground(); Drawable.ConstantState state = rippleDrawable.getConstantState(); try { Field colorField = state.getClass().getDeclaredField("mColor"); colorField.setAccessible(true);