Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/colorPrimary"
- android:id="@+id/toastRoot"
- xmlns:app="http://schemas.android.com/apk/res-auto">
- <TextView
- android:id="@+id/textViewInToast"
- app:layout_constraintTop_toTopOf="parent"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- <SeekBar
- android:id="@+id/seekBarInToast"
- app:layout_constraintTop_toBottomOf="@id/textViewInToast"
- app:layout_constraintLeft_toLeftOf="parent"
- android:max="100"
- android:layout_width="320dp"
- android:layout_height="wrap_content" />
- </android.support.constraint.ConstraintLayout>
- package com.example.mkaya.lab2april2019;
- import android.support.design.widget.Snackbar;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.RadioButton;
- import android.widget.SeekBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.widget.ToggleButton;
- public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
- private TextView textView;
- private ToggleButton toggleButton;
- private SeekBar seekBar;
- private Integer oldValue=50;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- textView=findViewById(R.id.scoretxt);
- toggleButton=findViewById(R.id.disable_snack);
- seekBar=findViewById(R.id.mySeekBar);
- seekBar.setOnSeekBarChangeListener(this);
- }
- @Override
- public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
- textView.setText(Integer.toString(seekBar.getProgress()));
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- oldValue=seekBar.getProgress();
- }
- @Override
- public void onStopTrackingTouch(final SeekBar seekBar) {
- if(toggleButton.isChecked()){
- Snackbar snackbar=Snackbar.make(seekBar,"Pregress Changed",Snackbar.LENGTH_LONG)
- .setAction("UNDO", new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- textView.setText(Integer.toString(oldValue));
- seekBar.setProgress(oldValue);
- Snackbar snackbar1=Snackbar.make(view,"Progress reset",Snackbar.LENGTH_SHORT);
- snackbar1.show();
- }
- });
- snackbar.show();
- }
- }
- public void CreateToast(View view) {
- RadioButton simpleRB=findViewById(R.id.rb_simple);
- if(simpleRB.isChecked()){
- Toast t=Toast.makeText(this, "Simple Toast!", Toast.LENGTH_SHORT);
- t.show();
- }
- else
- {
- //create a custome toast message
- LayoutInflater inflater=getLayoutInflater();
- View layout=inflater.inflate(R.layout.custom_toast,(ViewGroup)findViewById(R.id.toastRoot));
- SeekBar seekBarInToast=layout.findViewById(R.id.seekBarInToast);
- seekBarInToast.setProgress(seekBar.getProgress());
- TextView textViewInToast=layout.findViewById(R.id.textViewInToast);
- textViewInToast.setText(((Integer)seekBar.getProgress()).toString());
- Toast toast=new Toast(this);
- toast.setGravity(Gravity.BOTTOM,0,0);
- toast.setDuration(Toast.LENGTH_LONG);
- toast.setView(layout);
- toast.show();
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout 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"
- tools:context=".MainActivity">
- <TextView
- android:id="@+id/scoretxt"
- android:text="50"
- app:layout_constraintTop_toTopOf="parent"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- <ToggleButton
- android:id="@+id/disable_snack"
- app:layout_constraintTop_toBottomOf="@id/scoretxt"
- app:layout_constraintLeft_toLeftOf="parent"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <SeekBar
- android:id="@+id/mySeekBar"
- android:max="100"
- android:progress="50"
- app:layout_constraintLeft_toRightOf="@id/disable_snack"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="@id/disable_snack"
- app:layout_constraintBottom_toBottomOf="@id/disable_snack"
- android:layout_width="0dp"
- android:layout_height="0dp" />
- <RadioGroup
- android:id="@+id/rb"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintTop_toBottomOf="@id/disable_snack"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <RadioButton
- android:id="@+id/rb_simple"
- android:checked="true"
- android:text="Simple"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <RadioButton
- android:id="@+id/rb_custom"
- android:text="Custom"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </RadioGroup>
- <Button
- android:id="@+id/createToastBtn"
- app:layout_constraintLeft_toRightOf="@id/rb"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="@id/rb"
- app:layout_constraintBottom_toBottomOf="@id/rb"
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:text="Create Toast"
- android:XonClick="CreateToast"/>
- </android.support.constraint.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement