如何设置进度对话框的背景图像? [英] how to set background image for progress dialog?
本文介绍了如何设置进度对话框的背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Android ..
在我的应用我使用的是进度对话框。我想设置背景图像进度对话框。如何实现这一点?
上preExecute保护无效(){
super.on preExecute();
pDialog =新ProgressDialog(FrontActivity.this);
pDialog.setMessage(载入牌号请稍候......);
pDialog.setIndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
解决方案
这是我的自定义进度对话框布局:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / LinearLayout中
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =中心
机器人:背景=@布局/ custom_rounded_box
机器人:方向=垂直><的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =6
机器人:方向=横向> <进度
机器人:ID =@ + ID /进步
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_vertical | CENTER_HORIZONTAL
机器人:indeterminateDrawable =@绘制/ progress_background/> <的TextView
机器人:ID =@ + ID / DIALOGTITLE
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =3
机器人:重力=CENTER_HORIZONTAL | center_vertical
机器人:文字=
机器人:TEXTSIZE =22sp
机器人:文字样式=大胆/> <进度
机器人:ID =@ + ID /进步
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =05
机器人:背景=@机器人:彩色/黑白
机器人:indeterminateDrawable =@绘制/ progress_background
机器人:知名度=隐形/>
< / LinearLayout中><的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.5
机器人:方向=垂直> < ImageView的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/ light_gray_line>
< / ImageView的> <的TextView
机器人:ID =@ + ID / dialogMessage
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_below =@ + ID / DIALOGTITLE
机器人:可聚焦=真
机器人:focusableInTouchMode =真
机器人:重力=center_vertical
机器人:MAXLINES =10
机器人:填充=10dip
机器人:滚动条=垂直
机器人:文字=
机器人:TEXTSIZE =18sp>
< / TextView的>
< / LinearLayout中>< RelativeLayout的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =CENTER_HORIZONTAL
6:机器人layout_weight => <的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
机器人:方向=横向> <按钮
机器人:ID =@ + ID / OkButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / dialogMessage
机器人:layout_centerHorizontal =真
机器人:layout_marginLeft =10dip
机器人:layout_marginRight =10dp
机器人:背景=@绘制/ ok_btn>
< /按钮> <按钮
机器人:ID =@ + ID / cancelButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / dialogMessage
机器人:layout_centerHorizontal =真
机器人:layout_marginLeft =10dp
机器人:layout_marginRight =10dip
机器人:背景=@绘制/ cancel_btn/>
< / LinearLayout中>
< / RelativeLayout的> < / LinearLayout中>`
这是我的自定义对话框类
公共类CustomizeDialog扩展对话框实现OnClickListener {
按钮okButton;
上下文mContext;
TextView的mTitle = NULL;
TextView的mMessage = NULL;
视图V = NULL;
按钮cancelButton;
进度进度;公共CustomizeDialog(上下文的背景下){
超级(上下文);
mContext =背景;
/ **'Window.FEATURE_NO_TITLE - 用于隐藏mTitle * /
requestWindowFeature(Window.FEATURE_NO_TITLE);
/ **设计在对话框中main.xml中的文件* /
的setContentView(R.layout.custom_dialog_box);
V = getWindow()getDecorView()。
v.setBackgroundResource(android.R.color.transparent);
mTitle =(的TextView)findViewById(R.id.dialogTitle);
mMessage =(的TextView)findViewById(R.id.dialogMessage);
okButton =(按钮)findViewById(R.id.OkButton);
cancelButton =(按钮)findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(本);
okButton.setOnClickListener(本);
进度=(进度)findViewById(R.id.progress);}@覆盖
公共无效的setTitle(CharSequence的标题){
super.setTitle(职称);
mTitle.setText(职称);
}@覆盖
公共无效的setTitle(INT titleId){
super.setTitle(titleId);
mTitle.setText(mContext.getResources()的getString(titleId));
}/ **
*设置此对话框窗口的消息文本。
*
* @参数消息
* - 新的消息,在标题显示。
* /
公共无效setMessage(CharSequence的消息){
mMessage.setText(消息);
mMessage.setMovementMethod(ScrollingMovementMethod.getInstance());
}/ **
*设置消息ID
*
* @参数MESSAGEID
* /
公共无效setMessage(INT MESSAGEID){
mMessage.setText(mContext.getResources()的getString(MESSAGEID));
mMessage.setMovementMethod(ScrollingMovementMethod.getInstance());
}@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根}
}
你可以通过标题和消息
使用它的任何活动 mCustomizeDialog =新CustomizeDialog(myActivity.this);
mCustomizeDialog.setTitle(标题);
mCustomizeDialog.setMessage(信息);
mCustomizeDialog.okButton.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
mCustomizeDialog.dismiss();
});
mCustomizeDialog.show();
希望这有助于你:)
I'm new to Android..
In my app I'm using a progress dialog. I want to set background image for progress dialog. How do I implement this?
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(FrontActivity.this);
pDialog.setMessage("Loading Grades. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
解决方案
This is my layout for custom progress dialog :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@layout/custom_rounded_box"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".6"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:indeterminateDrawable="@drawable/progress_background" />
<TextView
android:id="@+id/dialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal|center_vertical"
android:text=""
android:textSize="22sp"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".05"
android:background="@android:color/black"
android:indeterminateDrawable="@drawable/progress_background"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/light_gray_line" >
</ImageView>
<TextView
android:id="@+id/dialogMessage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/dialogTitle"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:maxLines="10"
android:padding="10dip"
android:scrollbars="vertical"
android:text=""
android:textSize="18sp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight=".6" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<Button
android:id="@+id/OkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dialogMessage"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dp"
android:background="@drawable/ok_btn" >
</Button>
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dialogMessage"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dip"
android:background="@drawable/cancel_btn" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>`
And this is my custom Dialog class
public class CustomizeDialog extends Dialog implements OnClickListener {
Button okButton;
Context mContext;
TextView mTitle = null;
TextView mMessage = null;
View v = null;
Button cancelButton;
ProgressBar progressBar;
public CustomizeDialog(Context context) {
super(context);
mContext = context;
/** 'Window.FEATURE_NO_TITLE' - Used to hide the mTitle */
requestWindowFeature(Window.FEATURE_NO_TITLE);
/** Design the dialog in main.xml file */
setContentView(R.layout.custom_dialog_box);
v = getWindow().getDecorView();
v.setBackgroundResource(android.R.color.transparent);
mTitle = (TextView) findViewById(R.id.dialogTitle);
mMessage = (TextView) findViewById(R.id.dialogMessage);
okButton = (Button) findViewById(R.id.OkButton);
cancelButton = (Button) findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(this);
okButton.setOnClickListener(this);
progressBar = (ProgressBar) findViewById(R.id.progress);
}
@Override
public void setTitle(CharSequence title) {
super.setTitle(title);
mTitle.setText(title);
}
@Override
public void setTitle(int titleId) {
super.setTitle(titleId);
mTitle.setText(mContext.getResources().getString(titleId));
}
/**
* Set the message text for this dialog's window.
*
* @param message
* - The new message to display in the title.
*/
public void setMessage(CharSequence message) {
mMessage.setText(message);
mMessage.setMovementMethod(ScrollingMovementMethod.getInstance());
}
/**
* Set the message ID
*
* @param messageId
*/
public void setMessage(int messageId) {
mMessage.setText(mContext.getResources().getString(messageId));
mMessage.setMovementMethod(ScrollingMovementMethod.getInstance());
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
you can use it in any Activity by passing the title and message
mCustomizeDialog = new CustomizeDialog(myActivity.this);
mCustomizeDialog.setTitle("Title");
mCustomizeDialog.setMessage("Message");
mCustomizeDialog.okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCustomizeDialog.dismiss();
});
mCustomizeDialog.show();
Hope this helps you :)
这篇关于如何设置进度对话框的背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文