AlertDialog 自定義對話方塊檢視

dingcheng998發表於2016-11-24

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:text="12345678"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"

        android:gravity="center">
        <Button
            android:id="@+id/shop_item_subtract"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_margin="16dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:background="@drawable/subtract_grey"/>
        <EditText
            android:id="@+id/shop_item_edits"
            android:hint="1"
            android:layout_gravity="center"
            android:gravity="center"
            android:inputType="number"
            android:layout_width="72dp"
            android:layout_height="40dp"
            android:background="@drawable/text_rectangle03"/>
        <Button
            android:id="@+id/shop_item_plus"
            android:layout_margin="16dp"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:background="@drawable/plus_grey"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:orientation="horizontal">
        <Button
            android:id="@+id/shop_item_editcancel"
            android:text="取消"
            android:textColor="@color/white"
            android:layout_margin="4dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/text_rectangle02"/>
        <Button
            android:id="@+id/shop_item_sure"
            android:text="確定"
            android:textColor="@color/white"
            android:layout_margin="4dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/text_rectangle"/>
    </LinearLayout>
</LinearLayout>

AlertDialog dialog;
dialog = new AlertDialog.Builder(v.getContext()).create();
        dialog.setView(view);
        dialog.setCancelable(true);
        dialog.show();
        dialog.getWindow().setLayout(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.WRAP_CONTENT);//設定寬度和高度


相關文章