How to remove the text in progressBar in Android?

前端 未结 3 2018
忘了有多久
忘了有多久 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:13

    extra info:

    // wrong way

    progDialog.setProgressNumberFormat(null); // NullPointerException !!!
    progDialog.show();
    

    // right way

    progDialog.show();
    progDialog.setProgressNumberFormat(null);
    
    0 讨论(0)
  • 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);
        }
    }
    }
    
    0 讨论(0)
  • 2021-01-21 04:28
    progDialog.setProgressNumberFormat(null);
    progDialog.setProgressPercentFormat(null);
    
    0 讨论(0)
提交回复
热议问题