Home
Unlabelled
Change TextSize of EditText programmically
Change TextSize of EditText programmically
To set TextSize of EditText, call its setTextSize() method.
package com.example.androidedittext;
import android.os.Bundle;
import android.app.Activity;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText input = (EditText)findViewById(R.id.input);
input.setTextSize(28);
SeekBar seekbarScale = (SeekBar)findViewById(R.id.sbsize);
final TextView textScale = (TextView)findViewById(R.id.textsize);
seekbarScale.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int size = progress+1;
input.setTextSize(size);
textScale.setText(String.valueOf(size));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}});
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com" />
<SeekBar
android:id="@+id/sbsize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="50"
android:progress="28"/>
<TextView
android:id="@+id/textsize"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
0 komentar:
Posting Komentar