本篇文章给大家谈谈在android中创建带有进度条的对话框,以及在android中创建带有进度条的对话框是什么的知识点,同时本文还将给你拓展Android-创建带单选项列表的对话框、android–在
本篇文章给大家谈谈在android中创建带有进度条的对话框,以及在android中创建带有进度条的对话框是什么的知识点,同时本文还将给你拓展Android - 创建带单选项列表的对话框、android – 在警告对话框中显示进度条、android – 如何在对话框上添加进度条、android – 用于打开另一个对话框的对话框等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- 在android中创建带有进度条的对话框(在android中创建带有进度条的对话框是什么)
- Android - 创建带单选项列表的对话框
- android – 在警告对话框中显示进度条
- android – 如何在对话框上添加进度条
- android – 用于打开另一个对话框的对话框
在android中创建带有进度条的对话框(在android中创建带有进度条的对话框是什么)
我需要在对话框中添加进度条.因为可以删除或移动文件需要一些时间.如何添加进度条.请帮我.
样本屏幕截图: – (如何在绿色中添加进度条)
谢谢.
解决方法
Android - 创建带单选项列表的对话框


android – 在警告对话框中显示进度条
final AlertDialog.Builder alert = new AlertDialog.Builder(this); LinearLayout login = new LinearLayout(this); TextView tvUserName = new TextView(this); TextView tvPassword = new TextView(this); TextView tvURL = new TextView(this); final EditText etUserName = new EditText(this); final EditText etPassword = new EditText(this); final EditText etURL = new EditText(this); login.setorientation(1); // 1 is for vertical orientation tvUserName.setText(getResources().getString(R.string.username)); tvPassword.setText(getResources().getString(R.string.password)); tvURL.setText("SiteURL"); login.addView(tvURL); login.addView(etURL); login.addView(tvUserName); login.addView(etUserName); login.addView(tvPassword); etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); login.addView(etPassword); alert.setView(login); alert.setTitle(getResources().getString(R.string.login)); alert.setCancelable(true); alert.setPositiveButton(getResources().getString(R.string.login),new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog,int whichButton) { strhwdXml = etURL.getText().toString(); strUserName = etUserName.getText().toString(); XmlUtil.username = strUserName; strPassword = etPassword.getText().toString(); if ((strUserName.length() == 0) && (strPassword.length() == 0) && (strhwdXml.length() == 0)) { Toast.makeText( getBaseContext(),getResources().getString( R.string.userPassword),Toast.LENGTH_SHORT).show(); onStart(); } else { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor prefsEditor = prefs .edit(); try { StringBuffer inStreamBuf = new StringBuffer(); inStreamBuf = XmlUtil .getLoginAuthResponse(strUserName,strPassword,strhwdXml); strXmlResponse = inStreamBuf.toString(); Log.e("Response:",strXmlResponse); String parsedXML = ParseResponse(strXmlResponse); if (parsedXML .equalsIgnoreCase(getResources() .getString(R.string.success))) { }
解决方法
ProgressDialog dialog = ProgressDialog.show(MyActivity.this,"","Loading. Please wait...",true);
您可以阅读有关进度对话框here的更多信息
取消将是
dialog.dismiss();
This class was deprecated in API level 26. ProgressDialog is a modal dialog,which prevents the user from interacting with the app. Instead of using this class,you should use a progress indicator like ProgressBar,which can be embedded in your app’s UI. Alternatively,you can use a notification to inform the user of the task’s progress.For more details 07001
android – 如何在对话框上添加进度条
问题:我想在Dialog上显示此进度条,但Dialog始终显示在上面.这种情况可以做些什么?
public static void showProgressBar(@NonNull final Activity activity) { try { if (activity == null) { LogManager.printstacktrace(new NullActivityException()); return; } View view = activity.findViewById(android.R.id.content); if (view == null) { LogManager.printstacktrace(new NullPointerException("content view is null")); return; } View rootView = activity.findViewById(android.R.id.content).getRootView(); if (rootView == null || !(rootView instanceof ViewGroup)) { LogManager.printstacktrace(new NullPointerException("rootView is null or not an instance of ViewGroup")); return; } final ViewGroup layout = (ViewGroup) rootView; final ProgressBar progressBar = new ProgressBar(activity); progressBar.setIndeterminate(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable()); DrawableCompat.setTint(wrapDrawable,ContextCompat.getColor(activity,R.color.colorAccent)); progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable)); } RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT); final RelativeLayout rl = new RelativeLayout(activity); rl.setBackgroundColor(ActivityCompat.getColor(activity,R.color.tc_hint_grey_alpha)); rl.setClickable(true); rl.setTag("#$UniqueProgressBar"); ViewGroup.LayoutParams params2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,120); rl.setGravity(Gravity.CENTER); rl.addView(progressBar,params2); LogManager.i("ProgressBar","ProgressUtils.showProgressBar->called"); layout.addView(rl,params); mRunnable = new Runnable() { @Override public void run() { LogManager.i("ProgressBar","ProgressUtils.showProgressBar->120 secs timeout"); hideProgressBar(activity); } }; mHandler = new Handler(); mHandler.postDelayed(mRunnable,120000); LogManager.i("ProgressBar","Added"); } catch (Exception e) { LogManager.printstacktrace(e); } }
解决方法
public static void showProgressBar(@NonNull final Activity activity) { try { if (activity == null) { LogManager.printstacktrace(new NullActivityException()); return; } final WindowManager wm = (WindowManager) activity.getApplicationContext().getSystemService(Activity.WINDOW_SERVICE); final ProgressBar progressBar = new ProgressBar(activity); progressBar.setIndeterminate(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable()); DrawableCompat.setTint(wrapDrawable,R.color.colorAccent)); progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable)); } WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(); windowLayoutParams.gravity = Gravity.CENTER; windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; windowLayoutParams.token = activity.getwindow().getDecorView().getwindowToken(); windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; windowLayoutParams.height = LayoutParams.MATCH_PARENT; windowLayoutParams.width = LayoutParams.MATCH_PARENT; wm.addView(progressBar,windowLayoutParams); LogManager.i("ProgressBar","Added"); } catch (Exception e) { LogManager.printstacktrace(e); } }
android – 用于打开另一个对话框的对话框
在此示例中,如果此人选择“Choice1”,则应打开另一个对话框以询问更多问题.
我在下面有以下部分代码:
private void openDialog1() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Select Choice"); builder.setSingleChoiceItems(ChoiceLists.listofchoices,-1,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int item) { ccRewardDialog.dismiss(); String finalString = ""; if((ChoiceLists.listofchoices[item].equals("Choice1")) || (ChoiceLists.listofchoices[item].equals("Choice2"))) { openDialog2(); } TextView tv1 = (TextView) getActivity().findViewById(R.id.tv1); finalString = ChoiceLists.strRewards[item]; if(!RESULT.equals("")) //RESULT being a global value { finalString = finalString + "-" + RESULT; RESULT = ""; } tv1.setText(tv1.getText() + finalString + "\n"); } }); dialog1 = builder.create(); dialog1.show(); } private void openDialog2() { LayoutInflater li = LayoutInflater.from(getActivity()); View promptView = li.inflate(R.layout.reward_detail_prompt,null); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(promptView); final EditText userInput = (EditText) promptView.findViewById(R.id.etRewardDetail); builder.setCancelable(false); builder.setPositiveButton("OK",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { RESULT = userInput.getText().toString(); } }); builder.setNegativeButton("Cancel",int which) { RESULT = ""; //RESULT being a global value } }); }
如果我不这样做的话.你会怎么做呢?提前致谢.我正在继续学习更多知识,感谢所有的帮助
解决方法
private void openDialog2() { ... builder.create().show(); }
关于在android中创建带有进度条的对话框和在android中创建带有进度条的对话框是什么的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Android - 创建带单选项列表的对话框、android – 在警告对话框中显示进度条、android – 如何在对话框上添加进度条、android – 用于打开另一个对话框的对话框的相关知识,请在本站寻找。
本文标签: