android-drawable

Defined custom shape for button in xml. Now I want to change the color dynamically. How?

做~自己de王妃 提交于 2019-11-28 13:07:07
I have this: round_button.xml <xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:shape="oval"> <solid android:color="#dec60000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> <item android:state_pressed="false"> <shape android:shape="oval"> <solid android:color="#860000"/> <size android:width="150dp" android:height="150dp"/> </shape> </item> My Button: <Button android:id="@+id/incrementBTN" android:layout_width="wrap_content" android:layout_height="wrap_content"

How does ProgressBar drawable work?

偶尔善良 提交于 2019-11-28 12:36:44
Background I wanted to make a rounded progress bar that is determinate (meaning android:indeterminate="false" ), so I searched the Internet and found a short answer of Romain Guy, here . So I grabbed the code and used it in a sample project: the (part of the) layout file: <ProgressBar android:layout_width="50dp" android:layout_height="50dp" android:background="@color/backColor" android:indeterminate="false" android:indeterminateOnly="false" android:max="100" android:progress="33" android:progressDrawable="@drawable/progress" /> drawable/progress.xml <?xml version="1.0" encoding="utf-8"?>

How to draw a dot circle inside a square drawable in android?

天涯浪子 提交于 2019-11-28 12:18:17
问题 I want a small dot inside a square button , this is what i have tried till now as answered by azizbekian: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:width="100dp" android:height="100dp"/> <solid android:color="#38b0ef"/> </shape> </item> <item android:bottom="45dp" android:left="45dp" android:right="45dp" android:top="45dp"> <shape android:shape="oval"> <stroke android

how to add shadow effect on drawable in android

别来无恙 提交于 2019-11-28 10:47:02
I have created chat bubble with drawable which looks fine, now I want to add shadow effect below the drawable so it make 3d effect.I don't want to use 9-pitch image. I just want to know how i can add shadow effect on this drawable. my code is ----right_bubble_chat_drawable <?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="15dp" /> <solid android:color="@color/chatrightbubbleColor" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <size

How to return to default style on EditText if I apply a background?

我是研究僧i 提交于 2019-11-28 10:42:21
I just encountered with a problem that I don't know how to solve. It looks silly but I cannot find a way to fix it. I have a form in android with several EditText and when you submit the form it checks those EditText and if they have wrong data I change the EditText to red border (applying a ninepatch image). myEditText.setBackgroundResource(R.drawable.edittext_red); The problem is, I want to restore android's default style when the user change the EditText, but I don't know how to do it. if I do: myEditText.setBackgroundResource(0); It will just remove everything and that's not what I want.

Convert GradientDrawable to Bitmap

雨燕双飞 提交于 2019-11-28 09:48:09
问题 I have the following gradient (generated dynamically): GradientDrawable dynamicDrawable = new GradientDrawable(); dynamicDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); dynamicDrawable.setUseLevel(false); int colors[] = new int[3]; colors[0] = Color.parseColor("#711234"); colors[1] = Color.parseColor("#269869"); colors[2] = Color.parseColor("#269869"); dynamicDrawable.setColors(colors); and I want to set that drawable in a view using onDraw method. When I want to assign a Drawable

Android Zig-Zag layout

久未见 提交于 2019-11-28 09:29:47
I'm in need of creating a receipt layout in Android. The idea is very simple, a rectangle layout with a zigzag top. Even, i have tried dashed line but nothing working. <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:color="#FF00" android:dashWidth="5dp" android:dashGap="5dp" /> </shape> Try with this: https://github.com/beigirad/ZigzagView Support top and bottom Zigzag. <ir.beigirad.zigzagview.ZigzagView android:layout_width="match_parent" android:layout_height="240dp" app:zigzagBackgroundColor="#8bc34a" app:zigzagElevation="8dp" app

Get drawable of image button

喜夏-厌秋 提交于 2019-11-28 09:20:15
问题 How can I get the drawable of an Image Button to compare and do something if the drawable is A and something if is B?. Thank you so much. switch(getDrawableId(buttonRepeat)) { case R.drawable.a: mediaPlayer.setLooping(true); break; case R.drawable.b: mediaPlayer.setLooping(false); break; default: break; } 回答1: Use getDrawable() method in ImageButton and compare them using .getConstantState().equals() Sample code: ImageButton btn = (ImageButton) findViewById(R.id.myImageBtn); Drawable drawable

What should i use for better performance, nine-patch or drawable xml resource?

喜你入骨 提交于 2019-11-28 09:17:33
What is the best way to set background for some view? For example 2 variants of backround: background with gradient, rounded corners and border background with just one color and rounded corners So which of variants would be better, nine-patch or drawable xml resource? My guess is, NinePatch would be slightly faster in most cases. Here's what I found. GradientDrawable (the one used for rects in xml) uses this code to call through to Canvas which in turn uses native call leading to SkCanvas , SkDraw and eventually SkScan and SkBlitter . On the other hand, NinePatch 's draw() has almost zero

Android: Change center of linear GradientDrawable via code

烂漫一生 提交于 2019-11-28 08:57:32
问题 EDIT: LOOK AT SOLUTION ABOVE i m freaking out. all i just want to do, is setting a linear GradientDrawable, which changes the vertical center of the gradient... drawing the gradient works fine, but how can i change the center of it?!? RelativeLayout bgScreen = (RelativeLayout) findViewById(R.id.player_screen); GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {startColor,endColor}); gd.setCornerRadius(0f); gd.setAlpha(200); bgScreen.setBackground