カスタム ProgressDialogを作って対応

結局ググっていつもの stack overflow…。

カスタム ProgressDialogを作って、onCreateで地道に数字とパーセントの TextViewを見つけて View.GONEで消すということらしい。
実際のコードはこんな感じ。

public class MyProgressDialog extends ProgressDialog {

	public MyProgressDialog(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("errorLog",
					"Failed to invoke the progressDialog method 'setVisibility' and set 'mProgressNumber' to GONE.",
					e);
		}
	}

}


これでスッキリ!


ちなみに View.GONE を View.INVISIBLE にするとプログレスバーの下に文字列が入る部分の余白ができる。
こんな感じ。

最初はこっちの方がバランスが良い気がしていたけど、やっぱりこの余白はいらないな〜と思って結局は View.GONE にした。