Recently, I am working on an Android project. Due to lack of experience, I often encounter many difficult problems. I like CSDN to check information and often see good articles to solve the problems smoothly, I will also collect articles that help me. Unfortunately, this time I encountered another problem. first look at the following picture: this is when I am logging on to the page, I call the ProgressDialog of the system to wait, but it looks very uncoordinated. The waiting picture on the left is too large, the text on the right is too small and looks awkward. Although there are no functional problems, I have obsessive-compulsive disorder and it seems like getting rid of it. However, after searching for a long time, I didn't find that there is a way to set the font of ProgressDialog. So I came to CSDN to find the solution again, but after looking for a long time, I did not see the desired results after several pages. I was so sad that all I found said that ProgressDialog can customize a View, defining a layout in layout and setting it to ProgressDialog is indeed a solution, but it is quite troublesome for me. I just want to wait for the effect and change the font, if you cannot write a layout, rewrite a ProgressDialog. Finally, let me think about it. You can set layout of ProgressDialog so you can also get his View. As a result, Dialog has a way to get the View:
public abstract View getDecorView () Added in API level 1 Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager. Note that calling this function for the first time "locks in" various window characteristics as described in
With the View, I can find the TextView and set the font size. Here is my implementation code:
/*** Display progress dialog box ** @ param message * @ param cancel whether the font size * @ param textsize */protected final void showProgressDialog (String message, boolean cancel, int textsize) {// TODO Auto-generated method stub mProgress = new ProgressDialog (this); mProgress. setMessage (message); mProgress. setCancelable (cancel); mProgress. setOnCancelListener (null); mProgress. show (); setDialogFontSize (mProgress, textsize);} private void setDialogFontSize (Dialog dialog, int size) {Window window Window = dialog. getWindow (); View view = window. getDecorView (); setViewFontSize (view, size);} private void setViewFontSize (View view, int size) {if (view instanceof ViewGroup) {ViewGroup parent = (ViewGroup) view; int count = parent. getChildCount (); for (int I = 0; I <count; I ++) {setViewFontSize (parent. getChildAt (I), size) ;}} else if (view instanceof TextView) {TextView textview = (TextView) view; textview. setTextSize (size );}}
Finally, let's see: