将字体设置为alertdialog

时间:2016-02-13 12:30:01

标签: android alertdialog typeface

我有一个alertdialog,我使用字体标题和消息以及alertdialog按钮。 问题是标题和消息视图与字体但按钮不是? 为什么 这是我的代码

public boolean functionInQuestion(MissingParameters ... parameters) {
    Typeface myTypeFace = Typeface.createFromAsset(getAssets(),"fonts/hhh.ttf");
    TextView mysite = new TextView(mainn.this);
    TextView fbpage = new TextView(mainn.this);
    TextView content5 = new TextView(mainn.this);
    TextView Mytitle5 = new TextView(mainn.this);

    mysite.setText("google");
    fbpage.setText("fb");
    Mytitle5.setText("google and facebook");
    content5.setText("linka to google and facebook");

    mysite.setTypeface(myTypeFace);
    fbpage.setTypeface(myTypeFace);
    content5.setTypeface(myTypeFace);
    Mytitle5.setTypeface(myTypeFace);

    AlertDialog.Builder builder = new AlertDialog.Builder(mainn.this);
    builder.setView(content5);
    builder.setCustomTitle(Mytitle5);
    builder.setIcon(R.drawable.about);

    builder.setPositiveButton(fbpage.getText(), new DialogInterface.OnClickListener() {  
        @Override  
        public void onClick(DialogInterface dialog, int which) { 
            // When LeftButton click, source implementing is put here.  
            String url = "http://www.facebook.com";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

    builder.setNeutralButton(mysite.getText(), new DialogInterface.OnClickListener() { 
        @Override
        public void onClick(DialogInterface dialog, int which) {  
            // When CenterButton click, source implementing is put here.
            String url = "http://www.google.com";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

    builder.show();
    return false;
}

1 个答案:

答案 0 :(得分:0)

试试这个,它必须工作:)

public boolean functionInQuestion(MissingParameters ... parameters) {
    Typeface myTypeFace = Typeface.createFromAsset(getAssets(),"fonts/hhh.ttf");
    TextView mysite = new TextView(mainn.this);
    TextView fbpage = new TextView(mainn.this);
    TextView content5 = new TextView(mainn.this);
    TextView Mytitle5 = new TextView(mainn.this);

    mysite.setText("google");
    fbpage.setText("fb");
    Mytitle5.setText("google and facebook");
    content5.setText("linka to google and facebook");

    mysite.setTypeface(myTypeFace);
    fbpage.setTypeface(myTypeFace);
    content5.setTypeface(myTypeFace);
    Mytitle5.setTypeface(myTypeFace);

    AlertDialog.Builder builder = new AlertDialog.Builder(mainn.this);
    builder.setView(content5);
    builder.setCustomTitle(Mytitle5);
    builder.setIcon(R.drawable.about);

    builder.setPositiveButton(fbpage.getText(), new DialogInterface.OnClickListener() {  
        @Override  
        public void onClick(DialogInterface dialog, int which) { 
            // When LeftButton click, source implementing is put here.  
            String url = "http://www.facebook.com";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

    builder.setNeutralButton(mysite.getText(), new DialogInterface.OnClickListener() { 
        @Override
        public void onClick(DialogInterface dialog, int which) {  
            // When CenterButton click, source implementing is put here.
            String url = "http://www.google.com";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

    Dialog dialog =builder.show();
                Button button = (Button) dialog.findViewById(android.R.id.button1);
                button.setTypeface(myTypeFace);
                Button button2 = (Button) dialog.findViewById(android.R.id.button3);
                button2.setTypeface(myTypeFace);
    return false;
}