【问题标题】:change progressdialog and alertdialog background in android?更改android中的progressdialog和alertdialog背景?
【发布时间】:2011-03-23 05:01:00
【问题描述】:

我的应用程序中有一个警报对话框和进度对话框。我希望我的进度对话框和警报对话框看起来与 iphone 中的相同。我怎样才能改变他们两个的背景来实现这一点?

编辑: 我也可以使用自定义视图来实现这种效果吗?扩展进度对话框类的东西.....? 谢谢你的帮助。

【问题讨论】:

标签: android android-alertdialog progressdialog


【解决方案1】:
【解决方案2】:

1) 创建一个自定义的 Dialog java 类,像上面这样:

您可以将以上内容简单的复制粘贴到新的Java文件中,无需更改。

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) 在您的布局文件夹中创建一个名为 dialog_progress 的新 .xml 文件,其中包含上述内容:

(只是一个简单的例子,看起来像android默认的进度对话框,但你可以创建自己的布局)

<?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)因此,如果您想使用它,只需在您的活动中添加以下代码:

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

当你想关闭它时,只需拨打mprogress.dismiss();

【讨论】:

    猜你喜欢
    • 2012-10-07
    • 2012-11-01
    • 2012-05-08
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    相关资源
    最近更新 更多