您可以使用自定義佈局創建對話框。
首先創建自定義佈局的對話框
例如
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dialogrectangle">
<TextView
android:id="@+id/sub_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="dimen/marginTop"
android:textSize="@dimen/invalidSize"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"
android:layout_marginBottom="dimen/marginBotom"
android:src="@drawable/okay"/>
是創建對話框類
public class ViewDialog {
public void showDialog(View activity,int width,int height){
final Dialog dialog = new Dialog(activity.getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.custom_dialog);
ImageView dialogButton = (ImageView) dialog.findViewById(R.id.okay);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
Window window = dialog.getWindow();
window.setLayout(width, height);
}
}
然後後,使用這些行顯示對話框,在其中你想要顯示
ViewDialog dialog = new ViewDialog();
dialog.showDialog(view,width,height);
讓我知道是否有幫助。 :)
爲您的應用創建自定義對話框...爲此,你必須製作xml(用戶界面佈局)文件並在對話框中充氣它 –