Styling the scrollbar thumb - android

I'm trying to change the outlook of the scrollbar thumb for a ListView.
I added the following property to the listview:
android:scrollbarThumbVertical="#drawable/scrollbar_vertical_thumb"
scrollbar_vertical_thumb.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient android:angle="0" android:endColor="#FF9900" android:startColor="#FF9900"/>
<corners android:radius="1dp" />
<size android:width="3dp" />
</shape>
After applying my gradient I noticed I have tho scrollbars or scrollbar thumbs, as you can see in following picture (at the beginning of the page there's the left one and then it changes to the second one):
It seems like I didn't override the theme style for the scrollbar thumb.
Does anybody know, what could be wrong?

Update your ListView by adding 'scrollbarThumbVertical' property,
android:scrollbarThumbVertical="#drawable/scrollbar_vertical_thumb"
Then add following to 'scrollbar_vertical_thumb.xml' in drawable folder,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient android:angle="0" android:endColor="#6699FF" android:startColor="#3333FF" />
<corners android:radius="1dp" />
<size android:width="10dp" />
</shape>

You've override the wrong property.
You should do this instead:
<item name="android:fastScrollThumbDrawable">#drawable/scrollbar_vertical_thumb</item>

Related

seekbar's background picture showed twice

Progress bar display twice.
My XML code:
Style :
How do I solve this problem?
you can add gradient like
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:endColor="#color/colorgreenheader"
android:centerColor="#color/color_neartowhite"
android:startColor="#color/color_grey_light" />
<corners android:radius="8sp" />
<size android:width="8sp"/>
<padding
android:left="0.5sp"
android:right="0.5sp" />
</shape>

How to design color boxes in android as shown in the image?

How can we display the colors as shown in the image where we can select more than one color ? The colored boxes must be checkboxes according to me but I am not able customize them
You need to define an xml resource in the drawable folder and use it in an imageView for instance for your question above it may look like this. Where by you use a shape called rectangle, giving it a solid colour as below and then also making the corner radius circular with 8dp. Then to display it you use an imageView and set it as a src. I have also added a stroke. Remove it if you dont need it!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#DFDFE0" />
<size
android:height="8dp"
android:width="16dp" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
<stroke
android:width="3dp"
android:color="#2E3135" />
<gradient
android:type="linear"
android:angle="0"
android:startColor="#f6ee19"
android:endColor="#115ede" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp"/>
<gradient
android:startColor="#2E3135"
android:centerColor="#000000"
android:endColor="#ffffff"
android:angle="180"/>
</shape>
Change the colour as your need.

Android LinearLayout background truns black

Hi i used linearlayout and its property android:background to make border color of it grey.
When i switch to android 4.1., from 6.0 layout background turns black (whole background not just 3dip like set).
border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dip"
android:color="#d3d3d3" />
</shape>
Any suggestions how to fix this?
You are missing the background color for your shape.
On newer Android versions this is transparent, but on older ones it is black.
Just add a transparent solid to your XML to fix this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent" />
<stroke
android:width="3dip"
android:color="#d3d3d3" />
</shape>
Just add property **<solid android:color="YOUR COLOR" />**
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dip"
android:color="#d3d3d3" />
<solid android:color="#F9671E" /> // for background color.You can change
</shape>

Listview divider margin

I'm trying to set a margin to a listview divider.
The divider is a dashed line:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="1dp"
android:dashWidth="1.5dp"
android:width="1dp"
android:color="#FF404040" />
<size android:height="3dp" />
</shape>
and a listview where i set the divider
<ListView
android:id="#+id/lv_news_feed_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:divider="#drawable/ch_dashed_line_divider"
/>
but I want a divider margin left and right.
I also tried to set a padding to the shape, but the listview is ignoring the padding.
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />
Is there any possibility to set a margin to the listview divider - except in the getView() of the Adapter?
Inset is the way to go
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="15dp"
android:insetRight="15dp" >
<shape
android:shape="line" >
<stroke
android:dashGap="1dp"
android:dashWidth="1.5dp"
android:width="1dp"
android:color="#FF404040" />
<size android:height="3dp" />
</shape>
</inset>
Use 'inset'.....
(list_divider.xml)
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="50dp"
android:insetRight="50dp" >
<shape>
<solid android:color="#color/orange" />
<corners android:radius="2.0dip" />
</shape>
</inset>
and in your list view add like this...
<ListView
android:dividerHeight="2dp"
android:divider="#drawable/list_divider"
...
/>
you can set the inset value as desired...
You can use the following idea:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/table_background"/>
</shape>
</item>
<item android:left="2dp" android:right="2dp">
... your shape here ...
</item> </layer-list>
It works for me. Hope it will help.
U can use Gradient to get Right and Left margin instead of stroke.. Try this sample it starts and ends with black, in centre u'll get White.. It appears like u've given margin
<gradient android:startColor="#000000" android:centerColor="#ffffff"
android:endColor="#000000" />
I don't believe it is possible :/ Although if you add your own drawable at the bottom of each list item and remove the ListViews divider you can customize it however you want :)
Create the folder res/drawable and create a new xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#666666"></solid>
</shape>
..Then use that drawable in you list item.
Or a really quick and dirty way would ofc to create a thin LinearLayout (or some other layout) with colored background at the bottom of the list item to fake a customizable ListView divider..
Not a proper sollution, just some fixit ideas ;)

Layout with different colors

I'd like to have a background color of a RelativeLayout similar to that of an image shown in the link below. Ignore the black strip in the bottom half of the image.
I don't want to use the image as a background of the layout. Can you give me an idea of how to proceed?
You can use gradient. Set different gradient in selector as you want. Done!
GradientDrawable.class
This is what you want, set your colors. Enjoy!
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="30dp">
<shape android:shape="rectangle" >
<corners
android:topRightRadius="8dip"
android:topLeftRadius="8dip" />
<gradient
android:startColor="#030303"
android:endColor="#3B3B3B"
android:angle="270" />
</shape>
</item>
<item android:top="30dp" >
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="8dip"
android:bottomRightRadius="8dip" />
<gradient
android:startColor="#4B5057"
android:endColor="#4B5059"
android:angle="270" />
<size android:height="30dp" />
</shape>
</item>
</layer-list>
just try with shape file structure. I think this may give the solution.
//save this below code as gradient and use as background of your layout as
android:background="#drawable/gradient"
//gradient.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#232323" android:endColor="#4B5059"
android:angle="270"/>
</shape>

Categories

Resources