如何减小AlertDialog.Builder标题字体大小和正按钮大小?

发布于 2024-12-27 09:47:42 字数 74 浏览 1 评论 0原文

是否可以减小 AlertDialog.Builder 标题字体大小和正按钮大小?如果是的话,请问我该怎么办?

Is it possible to reduce the AlertDialog.Builder title font size and positive button size? If yes, Just let me how to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琴流音 2025-01-03 09:47:42

关于字体大小,您可以使用这个:

SpannableStringBuilder ssBuilser = new SpannableStringBuilder("Sample");
StyleSpan span = new StyleSpan(Typeface.ITALIC);
ScaleXSpan span1 = new ScaleXSpan(1);
ssBuilser.setSpan(span, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssBuilser.setSpan(span1, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setTitle(ssBuilser);

builder.show();

您也可以设置自定义标题:

float size = 25;    

AlertDialog.Builder builder = new AlertDialog.Builder(this);    
final TextView myView = new TextView(getApplicationContext());
myView.setText("A Sample Title to Change Dialog Title");
myView.setTextSize(size);
builder.setCustomTitle(myView);

About font size you can use this:

SpannableStringBuilder ssBuilser = new SpannableStringBuilder("Sample");
StyleSpan span = new StyleSpan(Typeface.ITALIC);
ScaleXSpan span1 = new ScaleXSpan(1);
ssBuilser.setSpan(span, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssBuilser.setSpan(span1, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setTitle(ssBuilser);

builder.show();

Also You can set custom title:

float size = 25;    

AlertDialog.Builder builder = new AlertDialog.Builder(this);    
final TextView myView = new TextView(getApplicationContext());
myView.setText("A Sample Title to Change Dialog Title");
myView.setTextSize(size);
builder.setCustomTitle(myView);
扎心 2025-01-03 09:47:42

您可以创建自己的对话框,以便您可以根据需要设置布局:

    Dialog dialog = new Dialog(act,R.style.MyTheme);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setOwnerActivity(act);
    //In the layout XML you can set the text size or the button size. 
    dialog.setContentView(R.layout.dialog_layout);

    TextView text = (TextView) dialog.findViewById(R.id.text);
    //you can set your text size here
    text.setTextSize(mySize);
    text.setText("my text"); 


    Button ok = (Button) dialog.findViewById(R.id.ok);
    //you can change the button dimensions here
    ok.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            //actions
        }
    });

    dialog.show();

问候。

Yo can create youtr own dialog so you can set the layout as you want:

    Dialog dialog = new Dialog(act,R.style.MyTheme);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setOwnerActivity(act);
    //In the layout XML you can set the text size or the button size. 
    dialog.setContentView(R.layout.dialog_layout);

    TextView text = (TextView) dialog.findViewById(R.id.text);
    //you can set your text size here
    text.setTextSize(mySize);
    text.setText("my text"); 


    Button ok = (Button) dialog.findViewById(R.id.ok);
    //you can change the button dimensions here
    ok.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            //actions
        }
    });

    dialog.show();

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文