drawable

Programmatically change drawableLeft of Button

天涯浪子 提交于 2020-01-01 03:18:11
问题 I'm using a Button <Button android:id="@+id/zoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/trans" android:drawableLeft="@drawable/left_img" android:fontFamily="arial" android:text="My Name is " android:textSize="50sp" /> and changing its text color with : zoom.setTextColor(Color.parseColor("voilet")); but not able to understand how to change its image?? 回答1: Try this: int imgResource = R.drawable.left_img; button

9-Patch drawable dimensions Android. How do different densities handle the non-stretched areas?

筅森魡賤 提交于 2019-12-31 10:42:05
问题 Consider the above image. - The dotted line demarcates the 9-Patch png I will slice out of a photoshop file. I need it to create a popup box. - The box incorporates a dropShadow as shown by the measuring tool in this photo. - The pink lines are there to show how I will use the draw9Patch tool to create the 9-Patch. My question is : If I have a View "Container" with the 9-Patch for a background I need to ensure its children views are always inside the white box. I was going to use padding for

9-Patch drawable dimensions Android. How do different densities handle the non-stretched areas?

余生长醉 提交于 2019-12-31 10:41:13
问题 Consider the above image. - The dotted line demarcates the 9-Patch png I will slice out of a photoshop file. I need it to create a popup box. - The box incorporates a dropShadow as shown by the measuring tool in this photo. - The pink lines are there to show how I will use the draw9Patch tool to create the 9-Patch. My question is : If I have a View "Container" with the 9-Patch for a background I need to ensure its children views are always inside the white box. I was going to use padding for

Button Background Selector

余生长醉 提交于 2019-12-30 18:39:31
问题 I try to switch the background of Buttons if they are pressed. I build a Selector like the answer suggested here: Standard Android Button with a different color finally I want to put GradientDrawables inside, but for debug purposes I only want to set a color, to see it is working. Here is my Selector <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/red"/> <item android:state_focused="true" android

Button Background Selector

 ̄綄美尐妖づ 提交于 2019-12-30 18:39:04
问题 I try to switch the background of Buttons if they are pressed. I build a Selector like the answer suggested here: Standard Android Button with a different color finally I want to put GradientDrawables inside, but for debug purposes I only want to set a color, to see it is working. Here is my Selector <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/red"/> <item android:state_focused="true" android

Defining XML Parent Style of Gradient / Shape / Corners

半世苍凉 提交于 2019-12-30 03:20:10
问题 How can I define an easily reusable base shape (or gradient, or corners) in XML? I have a dozen or so drawable gradients that will be the same other than the start and end colors. I was hoping to define the identical stuff somewhere else and have an XML file for each different gradient that only defined the start and end colors. Is that possible? This is the base: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"

How to get a byte array from a drawable resource ?

守給你的承諾、 提交于 2019-12-29 08:49:15
问题 I would like to get a byte array from an jpeg image located in my res/drawable file ? Does anyone know how to do that please ? 回答1: Get a bitmap decodeResource(android.content.res.Resources, int) Then either compress it to ByteArrayOutputStream() or copyPixelsToBuffer and get your array from the buffer. http://developer.android.com/reference/android/graphics/Bitmap.html 回答2: Drawable drawable; Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new

Android ImageButton - determine what resource is currently set

北慕城南 提交于 2019-12-29 07:31:57
问题 Is there a way I can find what resource a particular ImageButton is set to, at any given time? For eg: I have an ImageButton that I set to R.drawable.btn_on onCreate. Later, at some point, the ImageButton gets set to R.drawable.btn_off . I want to be able to check what resource the ImageButton is set to in my code. Thanks Chris 回答1: Just use setTag() and getTag() to associate and retrieve custom data for your ImageView . 回答2: You could define your own class as a child of ImageButton , add a

Map Marker icon animation (Google Maps API V2 for Android)

天涯浪子 提交于 2019-12-29 07:19:36
问题 On a custom event, I need my Marker to update its drawable 6 times (basically, I want the Marker to grow and shrink 3 times with a delay of 0.5 s between each growth and each shrink) so it notifies the user of said event. Is there any way to achieve this without actually having to remove the Marker and adding it again with a different Drawable ? 回答1: I'm afraid there is no way to do it today without actually removing the marker and adding it again with another drawable. I have just done so

How can I set the drawableRight resource via code?

ぐ巨炮叔叔 提交于 2019-12-29 06:44:07
问题 I am trying to set an image on the right side of my button after the button has been clicked. I want to do this via code. I have seen how to change the background resource via code but I am not able to find any examples showing how to change the sides via code. Is it possible? 回答1: You need to use the public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom) method with null for any that are not needed. 回答2: Usually you can change using this Drawable draw