Is it possible to alter progress dialog's message or spinner position?

给你一囗甜甜゛ 提交于 2019-12-24 15:40:33

问题


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.



来源:https://stackoverflow.com/questions/35480018/is-it-possible-to-alter-progress-dialogs-message-or-spinner-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!