先上图:
图中选择头像和等待就是以对话框的形式出现的
等待对话框步骤
1 定义一个LoadingDialog继承DialogFragment
import android.app.Dialog;import android.os.Bundle;import android.support.v4.app.DialogFragment;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;import com.zsg.chatroom.R;/** * 登陆时 弹出的等待自定义对话框 */public class LoadingDialog extends DialogFragment{ private String mMsg = "Loading"; public void setMsg(String msg) { this.mMsg = msg; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_loading, null); TextView title = (TextView) view .findViewById(R.id.id_dialog_loading_msg); title.setText(mMsg); Dialog dialog = new Dialog(getActivity(), R.style.dialog); dialog.setContentView(view); return dialog; }}
2 定义dialog_loading布局文件
<?xml version="1.0" encoding="UTF-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="center" android:background="@drawable/dialog_loading_bg" > <View android:layout_width="160.0dip" android:layout_height="160.0dip" android:layout_centerInParent="true" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical" > <ProgressBar android:layout_width="46.0dip" android:layout_height="46.0dip" android:layout_gravity="center" android:layout_marginBottom="10.0dip" android:clickable="false" android:gravity="center" /> <TextView android:id="@+id/id_dialog_loading_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:lineSpacingExtra="3.0dip" android:text="asdf" android:textColor="#ffffffff" android:textSize="17.0sp" /> </LinearLayout></RelativeLayout>
3 在样式里 定义对话框样式
<!-- 设置登陆等待时的自定义对话框样式 --> <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <!-- 边框 --> <item name="android:windowIsFloating">true</item> <!-- 是否浮现在activity之上 --> <item name="android:backgroundDimEnabled">false</item> <!-- 模糊 --> <item name="android:windowIsTranslucent">false</item> <!-- 半透明 --> <item name="android:windowNoTitle">true</item> <!-- 无标题 --> <item name="android:windowBackground">@android:color/transparent</item> <!-- 背景透明 --> </style>