Reputation: 1512
I'm using this library for progress indicator while I do the background work via web service. I want to make the background transparent while the progressbar is showing. Is there any way to make the window transparent programmatically just like it does with progress dialog?
public class MainActivity extends AppCompatActivity{
private EditText email, pass;
private SessionManager session;
private SQLiteHandler db;
private AVLoadingIndicatorView pb;
private static final String LOGIN = "http://ubooktoday.com/android/login";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email = (EditText)findViewById(R.id.et1);
pass = (EditText)findViewById(R.id.et2);
session = new SessionManager(getApplicationContext());
db = new SQLiteHandler(getApplicationContext());
pb = new AVLoadingIndicatorView(this);
if (session.isLoggedIn()) {
startActivity(new Intent(MainActivity.this, ListVActivity.class));
finish();
}
}
public void login(View view){
if (!email.getText().toString().equals("") && !pass.getText().toString().equals("")) {
loginRequest();
}else{
Toast.makeText(getApplicationContext(), "Please enter the details", Toast.LENGTH_SHORT).show();
}
}
private void loginRequest() {
startAnim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
stopAnim();
try {
JSONObject jObj = new JSONObject(response);
String status = jObj.getString("status");
// Now check status value
if (status.equals("0")) {
Toast.makeText(getApplicationContext(), jObj.getString("message"), Toast.LENGTH_LONG).show();
} else if (status.equals("1")) {
session.setLogin(true);
db.addUser(jObj.getString("spa_name"), jObj.getString("user_id"));
startActivity(new Intent(MainActivity.this, ListVActivity.class));
finish();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "VolleyError" + error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("email", email.getText().toString());
params.put("pass", pass.getText().toString());
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
}
public void startAnim(){
findViewById(R.id.avloadingIndicatorView).setVisibility(View.VISIBLE);
}
public void stopAnim(){
findViewById(R.id.avloadingIndicatorView).setVisibility(View.GONE);
}
}
Upvotes: 2
Views: 12463
Reputation: 3486
Try this . Make a custom dialog class
public class CShowProgress {
public static CShowProgress mCShowProgress;
public Dialog mDialog;
public CShowProgress() {
}
public static CShowProgress getInstance() {
if (mCShowProgress== null) {
mCShowProgress= new CShowProgress();
}
return mCShowProgress;
}
public void showProgress(Context mContext) {
mDialog= new Dialog(mContext);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.custom_progress_layout);
mDialog.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mDialog.setCancelable(true);
mDialog.setCanceledOnTouchOutside(true);
mDialog.show();
}
public void hideProgress() {
if (mDialog!= null) {
mDialog.dismiss();
mDialog= null;
}
}
}
Corresponding XML custom_progress_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/transparent"
android:orientation="vertical">
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/progress_bar"
app:indicator="SemiCircleSpin"
app:indicator_color="@android:color/black"
android:layout_width="50dp"
android:layout_height="50dp"
android:visibility="visible" />
</RelativeLayout>
And the Activity
CShowProgress cShowProgress = CShowProgress.getInstance();
cShowProgress.showProgress(Activity.this);
and hide by calling
cShowProgress.hideProgress();
Hope this will help.
Upvotes: 5
Reputation: 4335
Try this way:
ProgressDialog pd = new ProgressDialog(Login.this,R.style.MyProgressTheme);
pd.setCancelable(false);
pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
pd.show();
And create Theme in values\styles.xml
<style name="MyProgressTheme" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">@style/MyDialogStyle</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">12sp</item>
</style>
And also add this Theme in values\styles.xml
<style name="MyDialogStyle">
<item name="android:bottomBright">@color/transparent</item>
<item name="android:bottomDark">@color/transparent</item>
<item name="android:bottomMedium">@color/transparent</item>
<item name="android:centerBright">@color/transparent</item>
<item name="android:centerDark">@color/transparent</item>
<item name="android:centerMedium">@color/transparent</item>
<item name="android:fullBright">@color/transparent</item>
<item name="android:fullDark">@color/transparent</item>
<item name="android:topBright">@color/transparent</item>
<item name="android:topDark">@color/transparent</item>
</style>
And add values\colors.xml
<color name="transparent">#00000000</color>
EDIT 1
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/avloadingIndicatorView"
android:layout_width="wrap_content" //or your custom size
android:layout_height="wrap_content" //or your custom size
android:visibility="visible" //visible or gone
app:indicator="BallPulse"
app:indicator_color="your color"
android:background="@android:color/transparent"
/>
this might helps you.
Upvotes: 0