我想在点击按钮调整弹出搜索栏对话框时更改TextView的大小。
为清晰起见,请参阅图片。
我在How do I put a seek bar in an alert dialog?和Show progress of seekbar in a textview inside a custom alert dialog搜索了解决方案,这是我的代码:
btn_font.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_change_fontsize,
(ViewGroup) findViewById(R.id.layout_viewdetailcontent));
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ViewDetailActivity.this)
.setView(layout);
final SeekBar sb = (SeekBar) layout.findViewById(R.id.seekBar1);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
// Do something here with new value
p = progress;
tv_content.setTextSize(p);
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
p = 16;
tv_content.setTextSize(p);
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
if (p < 16) {
p = 16;
sb.setProgress(p);
}
Toast.makeText(getBaseContext(), String.valueOf(p),
Toast.LENGTH_SHORT).show();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
但是没有用。请帮我找一下我做错了什么。提前谢谢。
答案 0 :(得分:0)
button = findViewById(R.id.btn);
txt = findViewById(R.id.Tv);
txt.setText("Thank you, This is John Puwein");
txt.setTextSize(10);
txt.setGravity(Gravity.CENTER);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
AlertDialog.Builder ADB = new AlertDialog.Builder(context);
SeekBar seekbar = new SeekBar(context);
seekbar.setMin(10);
seekbar.setMax(100);
seekbar.setKeyProgressIncrement(1);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
int i = 0;
@Override
public void onProgressChanged(SeekBar sb2, int intger, boolean id)
{
i = intger;
txt.setTextSize(i);
}
@Override
public void onStartTrackingTouch(SeekBar sb)
{
Toast.makeText(getApplicationContext(), "" + i, Toast.LENGTH_SHORT).show();
}
@Override
public void onStopTrackingTouch(SeekBar sb)
{
sb.setProgress(i);
}
});
ADB.setView(seekbar);
ADB.show();
}
});