I have the default circle ProgressBar:
https://i.stack.imgur.com/DlYL4.png
I would like to change the thickness, color and the corner radius (in an XML) Already, found some examples, but they don't work with the default circle.
Thank you very much!
Create an xml file in drawable folder.
Drawable XML file
progress_bar_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="2dp"
android:useLevel="false">
<gradient
android:type="sweep"
android:useLevel="false"
android:startColor="#ff00ff"
android:endColor="#00ffffff"
android:angle="0"/>
</shape>
</rotate>
Start color and end Color of gradient you should change according to your need.
To change the thickness of progress bar you change the thickness using android:thickness attribute of shape.
And add code to your layout xml file.
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="30dp"
android:layout_height="30dp"
android:indeterminateDrawable="#drawable/progress_bar_bg" />
android:layout_width and android:layout_height should be change according to your need.
I hope its Work for you.
Related
There are numerous threads for creating a bordered button in this forum.
It works for example perfect with this xml-file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFEB3B" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#000000"/> `<!--Border-->`
</shape>
where i fail is the following:
i need 2 bordered buttons, one is yellow, the other one blue. Due to program logic I want to switch the colors, the yellow one gets blue, the blue one to yellow.
in the xml-file
<solid android:color="#FFEB3B" />`<!--Background Color-->`
is used.
In Kotlin I only find
button.setBackgroundColor(Color.YELLOW)
But I find nor button.setColor oder button.setdologColor or anything else.
Using setBackgroundColor, the color changes, but the border disappears. Which statement would keep the border?
I solved it with
punktelinks.setBackgroundResource(R.drawable.shapecolory)
in code and with resource
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFF00" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#000000"/> `<!--Border-->`
</shape>
This works (for me)
I am the newly in android studio.
Just reading and studying in regards to the gradient usage.
Is it possible to use gradient colour for the floating button for it to fill the whole shape?
As well, is it possible to create the text view style using gradient colour?
of course create a background.xml drawable folder and write the code below
<?xml version="1.0" encoding="utf-8"?>
<shape>
<gradient android:startColor="#color/colorAccent"
android:centerColor="#color/colorAccent"
android:endColor="#color/black"
android:angle="90"/>
<corners android:radius="10dp"></corners>
</shape>
I currently have the following xml file in my /res/drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#color/transparent_white" />
<stroke
android:width="1dip"
android:color="#color/light_gray" />
</shape>
Sometimes I would like the background to be white, gray, blue etc. depending on the item I am trying to border. Is there a way to do this without creating n number of xml files where the only difference is the color of the solid attribute?
you could do this by dynamically declaring the shape and changing the color at runtime.
ShapeDrawable shapeDrawable= new ShapeDrawable();
shapeDrawable.setShape(new RectShape());
shapeDrawable.getPaint().setColor(<your color>);
((TextView) row.findViewById(<your viewid>)).setBackgroundDrawable(shapeDrawable);
I have following myRec.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<corners android:radius="1dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="0dp"/>
<stroke
android:color="#color/my_button_border"
android:width="1dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
</selector>
.... and would like to create the same shape programmatically so that I can freely change color in runtime. How can I achieve it? Much thanks in advance
Take a look at the android.graphics.drawable.ShapeDrawable class and the Shape class subclasses, suchs as:
PathShape
RectShape
ArcShape
OvalShape
RoundRectShape
ShapeDrawable receives a shape in the constructor, and then you have a lot of function to modify the shape. Also, you can retrieve the Paint asociated to the ShapeDrawable so you can alter things like the color and so.
Also, take a look at this small example:
http://www.edumobile.org/android/android-tutorial/shape-drawing-example-in-android/
where you can see some diferent shapes, and some efects suchs as the CornerPathEffect,
Use shapedrawable, gradientdrawable with
http://developer.android.com/reference/android/graphics/CornerPathEffect.html
How can we change the background colour of a Border less button when the button is pressed.
I used this:
android:background="?android:attr/selectableItemBackground"
android:text="#string/btn_skip"
Where my button Displays a label "SKIP" as defined in my "strings.xml".
Now When I test this it is Good Except It shows default "Blue" Colour when in Pressed State.
I want it to match it with other elements of my My UI theme that are "Orange" "#FF8800"
Any Ideas?
Thankx in advance...!
instead of using ?android:attr/selectableItemBackground you can create a xml in drawable in folder with following content.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/orange"/>
<item
android:state_enabled="false"
android:drawable="#color/default"/>
<item
android:drawable="#color/default"/>
</selector>
Updated:
so you save this files as : btn_drawable.xml in drawable folder.
Simply replace ?android:attr/selectableItemBackground
with *#drawable/btn_drawable.xml*
Thanks #Nimish-Choudhary ...! I followed your advice. and I have explained it further for clarity to all having same question as me as a beginner.
Create an xml with name say "btntransparent.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/pressed"/>
<item
android:state_enabled="false"
android:drawable="#color/defaultColor"/>
<item
android:drawable="#color/defaultColor"/>
</selector>
Next add the colors "pressed" and "defaultColor" to another xml say "colors.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed">#CCFF8800</color>
<color name="defaultColor">#00000000</color>
</resources>
Here "#CCFF8800" is my pressed state Translucent Orange and "#00000000" is the 100% Transparent Black (;-) thats invisible). You can find more about color codes at Color| Android Developers
Now put the "colors.xml" in values Folder and "btntransparent.xml" in drawable Folder.
Now the last step is to voila use it in the button as
<Button
android:id="#+id/id_btn_skip"
android:background="#drawable/transparentbtn"
android:onClick="skipToMain"
android:text="#string/btn_skip" />
And thats should do the job...!
Take care.
regards,
raisedadead
If I understand you correctly, what you could do is add new resource in #drawable for example my_ripple.xml
<?xml version="0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF8800">
</ripple>
Then simply set this as your background.
In your theme add the following:
<item name="android:selectableItemBackground">#FF8800</item>
to override the default blue.