如何从android ProgressDialog中删除标题和消息
在Android系统中,我想在登录时使用一个自定义的如何从android ProgressDialog中删除标题和消息,android,progress-bar,progressdialog,Android,Progress Bar,Progressdialog,在Android系统中,我想在登录时使用一个自定义的ProgressDialog对话框,而不需要标题和消息。我很难让它工作 我希望它像下面的gif(注意没有标题或消息): 我如何在代码中应用这一点 我拥有的代码(不起作用): <Progressbar android:id="@+id/progressBar2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterm
ProgressDialog
对话框,而不需要标题和消息。我很难让它工作
我希望它像下面的gif(注意没有标题或消息):
我如何在代码中应用这一点
我拥有的代码(不起作用):
<Progressbar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progress_custom"
android:indeterminateOnly="false" />
我想要它,这样当我登录时,这个对话框就会显示出来。以下是我如何使用它:
public class MainSerenaActivity extends Activity {
EditText uname;
EditText pass;
EditText server;
Button login;
String strUname;
String unamePass;
String strPass;
String strServer;
String strServer_fn;
String unamepass;
String uPass;
String encPass;
TextView reg_txt;
MyApplication app;
String passwde;
ProgressDialog pd;
CheckBox servercheck_btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// getActionBar().setDisplayHomeAsUpEnabled(true);
uname = (EditText) findViewById(R.id.user_edt_lg);
pass = (EditText) findViewById(R.id.pass_edt_lg);
server = (EditText) findViewById(R.id.server);
login = (Button) findViewById(R.id.login);
servercheck_btn = (CheckBox) findViewById(R.id.checkBox1);
pd=(ProgressBar)findViewById(R.id.progressBar2);
login.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
public void onClick(View v) {
strUname = uname.getText().toString().trim();
strPass = pass.getText().toString().trim();
MyApplication.setUserID(strUname);
MyApplication.setPassWord(strPass);
if (isInternetAvailable()) {
if ((uname.getText().toString()).equals("")
&& (pass.getText().toString()).equals("")) {
Toast toast = Toast.makeText(MainSerenaActivity.this,
"please enter username & password ",
Toast.LENGTH_LONG);
toast.show();
} else {
MyThread t = new MyThread(MainSerenaActivity.this, 0);
pd=ProgressDialog.show(MainSerenaActivity.this, "", "");
t.start();
Toast.makeText(MainSerenaActivity.this,
"Successfully login", Toast.LENGTH_SHORT)
.show();
uname.setText("");
pass.setText("");
server.setText("");
servercheck_btn.setChecked(false);
}
}
else {
Toast toast = Toast
.makeText(
MainSerenaActivity.this,
"No internet available.Please turn on the internet",
Toast.LENGTH_LONG);
toast.show();
}
}
});
}
public boolean isInternetAvailable() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class MyThread extends Thread {
Context con;
int but;
Intent in;
MyThread(Context con, int but) {
this.con = con;
this.but = but;
}
public void run() {
try {
switch (but) {
case 0:
in = new Intent(MainSerenaActivity.this, Second_Btn.class);
if (servercheck_btn.isChecked()) {
if ((server.getText().toString()).equals("")) {
Toast toast = Toast.makeText(
MainSerenaActivity.this,
"please enter server ", Toast.LENGTH_SHORT);
toast.show();
} else {
strServer = server.getText().toString().trim();
strServer_fn = "https://" + strServer;
MyApplication.setServer(strServer_fn);
}
} else {
if ((server.getText().toString()).equals("")) {
strServer_fn = url;
MyApplication.setServer(strServer_fn);
} else {
strServer = server.getText().toString().trim();
strServer_fn = url;
MyApplication.setServer(strServer_fn);
}
}
startActivity(in);
break;
}
}
catch (Exception e) {
}
pd.dismiss();
}
}
}
但gif仍然显示标题和消息。我只想要微调器,我该怎么做?首先创建一个活动indocator类。创建构造函数,如下所示
public ActivityIndicator(Context context) {
super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activityindicator_dialog);
setCancelable(true);
RelativeLayout main = (RelativeLayout) findViewById(R.id.main);
main.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
现在,无论您想在哪里设置“进度”对话框,请输入以下代码。您将自定义进度对话框
private static ActivityIndicator activityIndicator;
public static void hideActivityViewer() {
if (activityIndicator != null) {
activityIndicator.dismiss();
}
}
public static void showActivityViewer(Context context) {
if (activityIndicator == null) {
activityIndicator = new ActivityIndicator(context);
}
activityIndicator.show();
}
public static void clearDialogs() {
activityIndicator = null;
}
活动指示器的xml如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:gravity="center"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/main" android:background="@drawable/overlay_bck">
<TextView android:text="@string/loading"
android:textSize="15sp" android:textColor="#FFFFFF" android:id="@+id/text"
android:textStyle="bold" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center_horizontal"></TextView>
<ProgressBar android:id="@+id/progress" android:layout_below="@+id/text"
style="@android:style/Widget.ProgressBar" android:layout_centerHorizontal="true"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</RelativeLayout>
感谢arpit回答我的问题。我在代码中创建了ActivityIndicator类
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:gravity="center"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/main" android:background="@drawable/overlay_bck">
<TextView android:text="@string/loading"
android:textSize="15sp" android:textColor="#FFFFFF" android:id="@+id/text"
android:textStyle="bold" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center_horizontal"></TextView>
<ProgressBar android:id="@+id/progress" android:layout_below="@+id/text"
style="@android:style/Widget.ProgressBar" android:layout_centerHorizontal="true"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</RelativeLayout>