9

我从 java 代码创建了一个 ProgressDialog:

mProgressDialog = ProgressDialog.show(this, ..., ... , true);

我想更改消息文本的大小及其颜色,我该怎么做?

4

3 回答 3

33

您可以使用可跨字符串并设置可跨字符串的颜色和大小。使用可扩展字符串设置文本颜色和大小。

注意:确保字体大小不会太大而无法适应屏幕

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>

主要活动

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

    });



}
   }

在此处输入图像描述

或者

您可以使用自定义样式更改文本的颜色

样式.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>

在你的活动中

    ProgressDialog pd = new ProgressDialog(this,R.style.NewDialog);
于 2013-04-16T19:38:55.817 回答
7

您还可以使用:ContextThemeWrapper

例如:

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

<style name="DialogCustom">
    <item name="android:textSize">18sp</item>
</style>
于 2015-03-24T15:26:58.400 回答
0

试试这样

private void showProgressDialog() {

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

使用自定义布局

于 2013-04-16T17:34:53.587 回答