首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改对话框中标题文本的颜色和字体

更改对话框中标题文本的颜色和字体
EN

Stack Overflow用户
提问于 2014-02-13 15:36:17
回答 3查看 2.2K关注 0票数 1

我想在对话框中更改标题的字体和颜色,我想更改字体、大小和颜色,我该怎么办?

这是我的代码,

代码语言:javascript
运行
复制
ivworknggroup.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                final Dialog dialog = new Dialog(Ourwork.this);
                dialog.setContentView(R.layout.nggroup);
                dialog.setTitle("N.G.GROUP");

                TextView tvnggroup1 = (TextView) dialog.findViewById(R.id.tvnggroup1);

                TextView tvnggroup2 =(TextView)dialog.findViewById(R.id.tvnggroup2);

                Typeface typeFace1 =  Typeface.createFromAsset(getAssets(),"fonts/antennalight.ttf");
                tvnggroup1.setTypeface(typeFace1);
                Typeface typeFace =  Typeface.createFromAsset(getAssets(),"fonts/antennabold.ttf");
                tvnggroup2.setTypeface(typeFace);

                tvnggroup2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.nggroupindia.com/"));
                        startActivity(browserIntent);
                    }
                });
                dialog.show();

            }
        });

有人能帮我吗?谢谢你。

EN

回答 3

Stack Overflow用户

发布于 2015-09-09 14:30:48

我曾经遇到过类似的情况,但这就是为我解决问题的方法。

代码语言:javascript
运行
复制
Dialog sortDialog = new Dialog(getApplicationContext());
                sortDialog.setContentView(R.layout.adtype_alertdialog);
                sortDialog.setTitle("N.G.GROUP");
                int dividerId = sortDialog
                        .getContext()
                        .getResources()
                        .getIdentifier("android:id/titleDivider", null,
                                null);
                if (dividerId != 0) {
                    View divider = sortDialog.findViewById(dividerId);
                    divider.setBackgroundColor(getResources().getColor(
                            R.color.yellow));
                }
                TextView tv = (TextView) sortDialog
                        .findViewById(android.R.id.title);
                if (tv != null) {
                    tv.setTextColor(getResources().getColor(R.color.yellow));
                }
                sortDialog.show();

在SDK文件夹的alert_dialog.xml中找到的标识符中的android:id/titleDivider & android.R.id.title

票数 1
EN

Stack Overflow用户

发布于 2014-02-13 15:40:12

你应该使用自定义视图作为你的对话框的标题,也许这个链接可以帮助你how to include custom title view with in AlertDialog in android?

票数 0
EN

Stack Overflow用户

发布于 2014-02-13 16:05:39

试试这条路

代码语言:javascript
运行
复制
private String HALLOWEEN_ORANGE = "#FF7F27";

AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Message").show();

setTitle("Title").
setTitleColor(HALLOWEEN_ORANGE).

setDividerColor(HALLOWEEN_ORANGE).

TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(10);//to change font size
textView.setTextColor(Color.RED); // to change color
//to change font family
Typeface face = Typeface.createFromAsset(getAssets(),"font/fontFileName.ttf");
textView.setTypeface(face);
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21747915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档