单击按钮显示搜索栏对话框以更改textview textsize android

时间:2013-11-05 09:48:38

标签: android seekbar text-size

我想在点击按钮调整弹出搜索栏对话框时更改TextView的大小。

为清晰起见,请参阅图片。

enter image description here

我在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();

            }
        });

但是没有用。请帮我找一下我做错了什么。提前谢谢。

1 个答案:

答案 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();
            }
        });