2

我想在单击一个按钮时更改 TextView 的大小,该按钮又调用弹出搜索栏对话框。

为清楚起见,请参见图片。

在此处输入图像描述

我在如何在警报对话框中放置搜索栏?在自定义警报对话框内的文本视图中显示搜索栏的进度以查找解决方案,这是我的代码:

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

            }
        });

但不工作。请帮我找出我做错了什么。提前致谢。

4

1 回答 1

1
    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();
            }
        });
于 2019-01-12T20:26:37.230 回答