Created
March 18, 2021 20:07
-
-
Save codinginflow/21256a8838b492f8bb352e85d5807d14 to your computer and use it in GitHub Desktop.
SeekBar Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:padding="16dp" | |
tools:context="com.example.application.seekbartutorial.MainActivity"> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_above="@id/progressBar" | |
android:layout_centerHorizontal="true" | |
android:layout_marginBottom="24dp" | |
android:text="0%" | |
android:textSize="30sp" /> | |
<ProgressBar | |
android:id="@+id/progressBar" | |
style="?android:attr/progressBarStyleHorizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_above="@id/seekBar" | |
android:layout_alignParentStart="true" | |
android:layout_marginBottom="21dp" /> | |
<SeekBar | |
android:id="@+id/seekBar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentStart="true" | |
android:layout_centerVertical="true" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.application.seekbartutorial; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.ProgressBar; | |
import android.widget.SeekBar; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private TextView textView; | |
private ProgressBar progressBar; | |
private SeekBar seekBar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
textView = (TextView) findViewById(R.id.textView); | |
progressBar = (ProgressBar) findViewById(R.id.progressBar); | |
seekBar = (SeekBar) findViewById(R.id.seekBar); | |
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |
@Override | |
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |
progressBar.setProgress(progress); | |
textView.setText("" + progress + "%"); | |
} | |
@Override | |
public void onStartTrackingTouch(SeekBar seekBar) { | |
} | |
@Override | |
public void onStopTrackingTouch(SeekBar seekBar) { | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment