开发者

change progressdialog and alertdialog background in android?

i have a alertdialog and progress dialog in my application. i want m开发者_StackOverflow中文版y progress dialog and the the alert dialog to look the same as the ones in iphone. how can i change the background of both of them to achieve this?

Edit: Also can i achieve this effect using a custom view? Something that extends the progress dialog class.....? thank you for your help.


Check this answer : How can I change the background of Android alert dialogs? and change progressdialog background


1) Create a custom Dialog java class, like this one above:

You can simple copy and paste the above content to the new Java file, no changes are needed.

package com.your.app;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class CustomProgressDialog extends Dialog {

public Activity c;
public Dialog d;
private String progressTitle;
private String progressComments;
private TextView tvProgressTitle;
private TextView tvProgressComments;

public CustomProgressDialog(Activity a) {
    super(a);
    // TODO Auto-generated constructor stub
    this.c = a;
}
public CustomProgressDialog(Activity a,String progressTitle,String progressComments) {
    super(a);
    // TODO Auto-generated constructor stub
    this.progressTitle = progressTitle;
    this.progressComments = progressComments;
    this.c = a;
}

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_progress);
    tvProgressTitle = (TextView) findViewById(R.id.tvProgressTitle);
    tvProgressComments = (TextView)    findViewById(R.id.tvProgressComments);
    tvProgressTitle.setText(this.progressTitle);
    tvProgressComments.setText(this.progressComments);

}
}

2) Create a new .xml file called dialog_progress in your layout folder that has the above content:

(It's just a simple example that looks like the android default progress dialog, but you can create your own layout)

<?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="100dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#EDEDED"
android:orientation="vertical"
>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center"
    >
    <TextView

        android:layout_marginLeft="100dp"
        android:id="@+id/tvProgressTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_margin="10dp"
        android:text="Loading..."
        android:textColor="#000000"
        android:textSize="17dp"
        android:textStyle="bold"/>

</LinearLayout>

<View
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:visibility="visible"
    android:id="@+id/ctview2"
    android:background="#000000"
     />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >

    <ProgressBar
        android:layout_marginLeft="30dp"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
        />

    <TextView
        android:layout_marginLeft="15dp"
        android:textColor="#000000"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Please wait."
        android:id="@+id/tvProgressComments" />


</LinearLayout>

3) So if you want to use it , simple add in your activity this code:

CustomProgressDialog mprogress =  new CustomProgressDialog(MainActivity.this,"Loading...","Please wait.");
        mprogress.show();

And when you want to dismiss it, just call mprogress.dismiss();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜