개발 창고/Android

[Android] How to use SeekBar

로이제로 2024. 3. 24. 23:56
반응형


TOC is not supported in this version (ex.Mobile)


 One of the functions that I use often and not often is SeekBar. It is often applied when the maintenance options/settings are adjusted by magnification rather than numbers

Basic Usage

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <SeekBar
        android:id="@+id/mSeekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />
</RelativeLayout>

 

 If you register SeekBar like this, the screen applied as below is exposed.

Default SeekBar Images

 

 To use this in Activity, apply it as follows. This is the source that worked to call the current Progress value to LogCat when modifying SeekBar with SeekBar half-active.

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

        // STEP01. Match the SeekBar of layout
        SeekBar mSeekBar = findViewById(R.id.mSeekBar);

        // CASE01. If SeekBar has a default value of 50%
        mSeekBar.setProgress(50);

        // CASE02. If you want to process SeekBar values when modifying them
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
                Log.d("TAG", "Progress >> " + progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

Default 50% SeekBar Called
When modifying SeekBar, the above log is called.

How to change the SeekBar

If you want to change the color to SeekBar

First, add the corresponding sauce to <resources> in res > values > style.xml

    <style name="SeekBarColor" parent="Widget.AppCompat.SeekBar">
        <item name="colorAccent">#000000</item>
    </style>

If you want to changThen add android:theme to SeekBar.

    <SeekBar
        android:id="@+id/mSeekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:theme="@style/SeekBarColor"
        />

Then add android:theme to SeekBar.


[Android] How to use SeekBar

🇰🇷 Korean

2020.07.26 - [개발 창고/Android] - [Android] SeekBar 적용하기

 

[Android] SeekBar 적용하기

자주 쓰기도, 자주 쓰지 않기도 하는 기능 중 하나가 SeekBar인데요 주료 옵션/설정 등을 숫자가 아닌 배율로 조정할 경우 적용하는 경우가 많은데요 이렇게 SeekBar를 등록하면 아래와 같이 적용된

royzero.tistory.com

반응형