2012-01-16 145 views

回答

5

關於字體大小,你可以使用這個:

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); 
+0

它不適合me.i需要文本大小像12dp或14dp 。可以告訴我我該怎麼做 – Meghna 2014-05-27 04:46:00

+0

我已經更新了我的帖子,你可以試試。您可以使用顯示指標來獲取dp中的大小。例如:14 * getResources()。getDisplayMetrics()。density; – 2014-05-27 06:22:54

3

呦可以創建youtr自己的對話框,您可以設置佈局,只要你想:

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

問候。