Cara Menampilkan teks di android studio

Tutorial Android

Cara Menampilkan teks di android studio

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginTop="10dp"

android:orientation="vertical"

android:padding="10dp">

<TextView

android:id="@+id/textView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="2dp"

android:text="Welcome to Android tutorial"

android:textColor="#229954"

android:textSize="25dp"

android:textStyle="bold" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:textAllCaps="true" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif"

android:text="This Android tutorial is design for both begineers and Professional." />

<TextView

android:id="@+id/textView4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:autoLink="email|web"

android:text="Visit https://studentstutorial.com" />

</LinearLayout>

 

MainActivity.java

package com.example.seekbarexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.SeekBar;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private SeekBar sBar;

private TextView tView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

sBar = (SeekBar) findViewById(R.id.seekBar);

tView = (TextView) findViewById(R.id.textview);

tView.setText(sBar.getProgress() + "/" + sBar.getMax());

sBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

int pval = 0;

@Override

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

pval = progress;

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

//write custom code to on start progress

}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

tView.setText(pval + "/" + seekBar.getMax());

}

});

}

}

 

 

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *