爲了提高工作效率,對一些常見View的特殊用法作一下總結。
一、進度條對話框
1.使用系統的ProgressDialog
https://www.cnblogs.com/guop/p/5139937.html (圓形進度條與水平進度條)
注意創建ProgressDialog時不要使用Builder來創建,即:
new ProgressDialog.Builder(mContext).create();
用這種方式創建的ProgressDialog會不顯示進度條,只會顯示純文字。
2.使用AlertDialog自定義View
正確的用法:
progressDialog = new AlertDialog.Builder(mContext).create(); View rootView = LayoutInflater.from(mContext).inflate(R.layout.mprogress_dialog, null); pbBar = rootView.findViewById(R.id.pb_bar); tvMsg = (TextView) rootView.findViewById(R.id.tvMsg); progressDialog.setView(rootView);
注意錯誤的用法:
new ProgressDialog.Builder(mContext,ProgressDialog.THEME_DEVICE_DEFAULT_DARK).create();
上面的ProgressDialog.Builder實際上還是父類AlertDialog的類,create出來的是AlertDialog,並非ProgressDialog,無法將AlertDialog強制轉換成ProgressDialog。
也就無法使用ProgressDialog的特有方法progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER),因此,如果想通過Builder類創建的dialog來實現圓形進度條對話框,
只有自定義view。
3.繼承的方式