How to remove the text in progressBar in Android?

前端 未结 3 2017
忘了有多久
忘了有多久 2021-01-21 03:52

I have a progress bar in my app but it is showing some text default i want to remove the text. please help me how to remove the text.

Here is my code snippet:

         


        
3条回答
  •  北海茫月
    2021-01-21 04:16

    Create this class for Android < API Level 11 and use it instead the default ProgressDialog. It uses reflection to set the visbility to GONE:

    public class CustomProgressDialog extends ProgressDialog {
    
    public CustomProgressDialog(Context context) {
        super(context);
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        try {
            Method method = TextView.class.getMethod("setVisibility",
                    Integer.TYPE);
    
            Field[] fields = this.getClass().getSuperclass()
                    .getDeclaredFields();
    
            for (Field field : fields) {
                if (field.getName().equalsIgnoreCase("mProgressNumber")) {
                    field.setAccessible(true);
                    TextView textView = (TextView) field.get(this);
                    method.invoke(textView, View.GONE);
                }
    
                if (field.getName().equalsIgnoreCase("mProgressPercent")) {
                    field.setAccessible(true);
                    TextView textView = (TextView) field.get(this);
                    method.invoke(textView, View.GONE);
                }
            }
        } catch (Exception e) {
            Log.e(TAG,
                    "Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.",
                    e);
        }
    }
    }
    

提交回复
热议问题