Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

android - ProgressDialog: change text size

I create a ProgressDialog from java code:

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

I want to change the message text size and its color how can I do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use a spannable string and set the color and size for the spannable string. Use the spannable string to set text color and size.

Note: Make sure the font size is not too large to fit in the screen

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

OR

You can change the color of the the text by using a custom style

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>

In your activity

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...