SeekBar sets the thickness and color of the line from the code.

I want to create a search program fully programmatically. All formatting must be done from the code itself. I can’t even use extractable from xml files.

Everything works fine except for the line for the search bar. I can change the color of the line / change it to some available, etc., but I can not change the thickness of the line.

I get the following output:

output

But I want to achieve something like a thin line:

desired

+4
source share
2 answers

You can change the size / thickness of your search bar simply by using two search attributes. Which:

android:minHeight="2dip"

android:maxHeight="2dip"

For instance:

            <SeekBar
                android:progressDrawable="@drawable/seek_progress"
                android:thumb="@drawable/thumb"
                android:id="@+id/seekDistance"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:max="80"
                android:minHeight="2dip"
                android:maxHeight="2dip"
                />
+19
source

xml, "progress_drawable", xml.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <solid
                android:color="#bababa"/>
            <size
                android:height="13dp"
                android:width="13dp" />
            <corners android:radius="7dp" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid
                    android:color="@color/colorAccent"/>
                <corners android:radius="7dp" />
            </shape>
        </clip>
    </item>
</layer-list>

drawable , android: maxHeight

        <SeekBar
        android:id="@+id/sb"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="10"
        android:maxHeight="10dp"
        android:minHeight="10dp"
        android:progressDrawable="@drawable/progress_drawable"/>
0

Source: https://habr.com/ru/post/1539237/


All Articles