2013-04-16 72 views

Trả lời

31

Bạn có thể sử dụng một chuỗi spannable và thiết lập màu sắc và kích thước cho chuỗi spannable. Sử dụng chuỗi có thể chỉnh sửa để đặt màu và kích thước của văn bản.

Note: Đảm bảo kích thước phông chữ không phải là quá lớn để phù hợp với màn hình

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:layout_marginBottom="35dp" 
    android:layout_marginLeft="56dp" 
    android:text="Button" /> 

</RelativeLayout> 

MainActivity

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button b= (Button) findViewById(R.id.button1); 
    b.setOnClickListener(new OnClickListener() 
    { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      String s= "Hello"; 
      String title="MyTitle"; 
      SpannableString ss1= new SpannableString(title); 
      ss1.setSpan(new RelativeSizeSpan(2f), 0, ss1.length(), 0); 
      ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, ss1.length(), 0); 
      SpannableString ss2= new SpannableString(s); 
      ss2.setSpan(new RelativeSizeSpan(2f), 0, ss2.length(), 0); 
      ss2.setSpan(new ForegroundColorSpan(Color.GREEN), 0, ss2.length(), 0); 
      ProgressDialog pd = new ProgressDialog(MainActivity.this); 
      pd.setTitle(ss1); 
      pd.setMessage(ss2); 
      pd.show(); 
     } 

    }); 



} 
    } 

enter image description here

HOẶC

Bạn có thể thay đổi màu sắc của văn bản bằng cách sử dụng một phong cách tùy chỉnh

styles.xml

<style name="NewDialog" parent="@android:style/Theme.Dialog"> 

<item name="android:windowFrame">@null</item> 
<item name="android:windowBackground">@android:color/transparent</item> 
<item name="android:windowIsFloating">true</item> 
<item name="android:windowContentOverlay">@null</item> 
<item name="android:windowTitleStyle">@null</item> 
<item name="android:colorBackground">#ffffff</item>// change background color 
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
<item name="android:backgroundDimEnabled">true</item> 
<item name="android:width">600dip</item> 
<item name="android:height">100dip</item> 
<item name="android:textColor">#0FECFF</item>// change color 
</style> 

Trong hoạt động của bạn

ProgressDialog pd = new ProgressDialog(this,R.style.NewDialog); 
+0

thx để trả lời –

0

thử như

private void showProgressDialog() { 

    progressDialog = new ProgressDialog(this,R.style.CustomDialog); 
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
    progressDialog.setMessage("Logging in. Please wait."); 
    progressDialog.show(); 
} 

sử dụng custome bố trí này

4

Bạn cũng có thể sử dụng: ContextThemeWrapper

Ví dụ:

ProgressDialog.show(new ContextThemeWrapper(this, R.style.DialogCustom), "Loading", "Wait please"); 

<style name="DialogCustom"> 
    <item name="android:textSize">18sp</item> 
</style> 
Các vấn đề liên quan