How to create a custom circular seekbar with custom thumb? - java

Im trying to create a custom circular seekbar like this one:
I have the shape and the thumb xml done but the thumb isn't appearing when i put it in the layout xml.
Seekbar background xml (lap_counter.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle"
android:thicknessRatio="16"
android:useLevel="false">
<corners android:radius="500dp" />
<stroke
android:width="45dp"
android:color="#color/blue_secondary" />
</shape>
</item>
</layer-list>
Custom thumb xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/white">
<item>
<shape android:shape="oval">
<solid android:color="#color/white"/>
<stroke android:color="#color/orange" android:width="3dp"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
</layer-list>
But when apply the custom xml this are the results:
<androidx.appcompat.widget.AppCompatSeekBar
android:id="#+id/sb_lap_counter"
android:layout_width="700dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:progress="50"
android:background="#drawable/lap_counter"
android:thumb="#drawable/lap_counter_thumb"
tools:progress="50" />
I tried putting it in as a custom style in themes.xml but it doesn't work either.
What am i doing wrong?

You are using a seekbar.This only works for horizontal seeks.That orange thing is the thumbnail which you need.

Related

Android seekbar customize

I am trying to customize and android seekbar (using API 17) so that the whole progress bar line is blue.
I have created the following XML in res/drawable:
draw_seekbar_settings.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<clip>
<shape
android:shape="line">
<stroke
android:color="#color/progressFxBar"
android:width="2dp"
/>
</shape>
</clip>
</item>
</selector>
and
<SeekBar
android:id="#+id/t_seekbar"
android:layout_width="220dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:max="100"
android:progress="50"
android:progressDrawable="#drawable/draw_seekbar_settings"
The problem is only half the progress bar is blue, the other half doesn't have any colour whatsoever.
I would like to get this image
Instead I am getting this
change the draw_seekbar_settings.xml as follows:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape
android:shape="line">
<stroke
android:color="#color/progressFxBar"
android:width="2dp"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<!-- if you want to change the progress edit following -->
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>

why doesn't drawable apears on Button?

I am a newbie in Java-Android developing.
I want to add this drawable on a view like button's background
but it doesn't draw anything.
This is my background drawable_shining.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<gradient
android:endColor="#000"
android:centerColor="#111"
android:startColor="#000"
android:angle="45"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#555"
android:type="radial" />
</shape>
</item>
</layer-list>
[here is code and layout][1]
according to documentation layer-list is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.
Each drawable is represented by an element inside a single element.
in your code, write each <shape> in <item> tag. Your final code will be look like this,
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#333"
android:type="radial" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#333"
android:type="radial" />
</shape>
</item>
You can use same format like below code :
Reference : angrytools
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#47A891"
android:startColor="#E8E8E8"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>

Fading shade for ImageView border

How to achieve this in android? Any better waysFading shade border for imageview,imagebutton
You can create your own drawable to achieve this.
The code for your Border.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="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
Implement this in your layout by using android:background="#drawable/border".
Android also has some options.
android:background="#android:drawable/dialog_frame"
You could also use websites like http://inloop.github.io/shadow4android/ to achieve it. Here is tutorial for 9Patch: http://radleymarx.com/blog/simple-guide-to-9-patch/

Android Shape Rectangle with 2 colors

I need to make a custom rectangle that should use hex colors from #bff54a up to #88c010.
Actually I have this xml but I can only use one of those colors. How can I make the gradient possible? I already searched and I didn't found anything like this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<solid android:color="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
Thanks to all!
Use Gradient as the color of the Drawable :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<gradient
android:type="linear"
android:centerX="0"
android:centerY="1"
android:startColor="#bff54a"
android:endColor="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
See Drawable Resources
You can create file shape and implement this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangule"> <!-- oval -->
<gradient
android:startColor="#388E3C"
android:endColor="#448AFF"
android:centerColor="#color/colorPrimary"
/>
</shape>
</item>
</selector>
Result

Create own styles in Android

Every time I try to customize the style of a view I have the same problem.
What parameters can I change; and how to override the system defaults? For example:
How to change the highlighted color of a element of a ListView when clicked
How to change the default frame of a DialogFragment? I mean the frame that is removed with the Style DialogFragment.STYLE_NO_FRAME.
Where can I check what are the values I should play with for achieve my custom layouts?
Thanks
Well you can change the look by creating a new xml file in the drawable folder but dont make a layout xml jus pick andrid xml from the wizard and it will give u a list of components you can modify including colour.
<?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="#android:color/black" />
</shape>
</item>
<item android:top="1dp" android:left="2dp" android:right="2dp" android:bottom="25dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
</shape>
</item>
<item android:top="1dp" android:left="400dp" android:right="2dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
</item>
<item android:top="1dp" android:left="2dp" android:right="400dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
</item>
</layer-list>
then you can just change whats required!
But provider some code and i will be able to answer better..

Categories

Resources