android自定义对话框有背景,Android自定义对话框 还是会出现背景框

本文探讨了在Android应用中遇到的一个问题:将自定义的进度条对话框从测试程序移植到实际项目后,对话框的宽度没有正确设置为`match_parent`,并且出现了额外的背景框。作者提供了自定义对话框的布局文件和相关代码,并展示了正常与异常效果的截图。问题可能源于项目中其他样式或主题的影响,需要进一步排查资源引用和样式覆盖情况。
摘要由CSDN通过智能技术生成

请大牛指点

Android 自定义的进度条对话框,用AlertDialog实现,本人写一个测试程序,效果很正常,图片如下

http://fhr.luckcome.com/temp/01.png

但是将它移植到本人的项目后,对话框的宽度就不是设定的 match_parent 了,而且还多了一个背景框,不知道这个背景框是哪来的,都是自定义的,测试代码怎么就是正常的

http://fhr.luckcome.com/temp/02.png

下面是进度条对话框布局文件

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/dialog_bg1"

android:orientation="vertical" >

android:id="@+id/progressTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#0000ff"

android:text=""

/>

android:id="@+id/progressBar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

android:layout_marginBottom="10dp"

style="?android:attr/progressBarStyleHorizontal"

android:progressDrawable="@drawable/my_progress_bar"

android:max="100"

android:visibility="visible" />

下面是自定义的对话框类

package com.example.dialog20141118;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ProgressBar;

import android.widget.TextView;

public class MyProgressDialog {

private Context context;

private AlertDialog mDialog;

private View mView;

private LayoutInflater mInflater;

private AlertDialog.Builder mBuilder;

private TextView mTextView;

private String title;

private ProgressBar mProgressBar;

private int mProgress=0;

private int mSecondaryProgress=0;

private int mMax=100;

private int mVisibility=0;

/**

* 构造函数

* @param context

*/

@SuppressLint("InflateParams")

public MyProgressDialog(Context context,String title) {

this.context = context;

this.title = title;

mInflater = LayoutInflater.from(context);

mView = mInflater.inflate(R.layout.my_prgdlg_layout, null);

mBuilder = new AlertDialog.Builder(context);

mBuilder.setView(mView);

mDialog = mBuilder.create();

mDialog.setCanceledOnTouchOutside(false);

mProgressBar = (ProgressBar)mView.findViewById(R.id.progressBar);

mTextView = (TextView) mView.findViewById(R.id.progressTitle);

mTextView.setText(title);

}

/**

* 显示对话框

*/

public void show(){

mDialog.show();

}

/**

* 销毁对话框

*/

public void dismiss() {

mDialog.dismiss();

}

/**

* 进度条显示进程

*/

Thread progressRun = new Thread() {

@Override

public void run() {

while(true) {

mProgressBar.setProgress(mProgress);

}

}

};

/**

* 测试进程,配合 progressRun 进程使用

*/

Thread progressCount = new Thread() {

@Override

public void run() {

while(mProgress 

mProgress++;

try {

Thread.sleep(100);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

dismiss();

}

};

/**

* 启动进度条显示刷新进程

*/

void progressStrart() {

progressRun.start();

// 测试用,使进度条跑动

progressCount.start();

}

/**

* 获取对话框标题内容

* @return

*/

public String getTitle() {

return title;

}

/**

* 设置对话框标题

* @param title

*/

public void setTitle(String title) {

this.title = title;

}

/**

* 获取 进度条进度值

* @return

*/

public int getmProgress() {

return mProgress;

}

/**

* 设置进度条进度值

* @param mProgress

*/

public void setmProgress(int mProgress) {

this.mProgress = mProgress;

}

/**

* 获取第二进度的进度值

* @return

*/

public int getmSecondaryProgress() {

return mSecondaryProgress;

}

/**

* 设置第二进度的进度值

* @param mSecondaryProgress

*/

public void setmSecondaryProgress(int mSecondaryProgress) {

this.mSecondaryProgress = mSecondaryProgress;

}

/**

* 获取进度的满量程值

* @return

*/

public int getmMax() {

return mMax;

}

/**

* 设置进度的满量程值

* @param mMax

*/

public void setmMax(int mMax) {

this.mMax = mMax;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值