I basically want to put message text before progress bar (spinner) in progress dialog in order to look like snackbar.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There might be some easier way to do this that I'm not thinking of at the moment, but you could override the ProgressDialog
's onCreate()
method, and fiddle with the layout programmatically. For example:
ProgressDialog pd = new ProgressDialog(this) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressBar progress = (ProgressBar) findViewById(android.R.id.progress);
LinearLayout bodyLayout = (LinearLayout) progress.getParent();
TextView messageView = (TextView) bodyLayout.getChildAt(1);
LinearLayout.LayoutParams llp =
(LinearLayout.LayoutParams) messageView.getLayoutParams();
llp.width = 0;
llp.weight = 1;
bodyLayout.removeAllViews();
bodyLayout.addView(messageView, llp);
bodyLayout.addView(progress);
}
};
pd.setMessage("Testing...");
pd.show();
I had a quick look through the source versions, and I think this should work for pretty much all of 'em.