没有显示图象的对话框背景在机器人的整个背景中

时间:2013-06-26 13:29:28

标签: android android-layout android-dialog

我在android中创建了一个简单的对话程序,用于登录对话框,用于学习目的。我已成功运行并成功运行它但问题是我想要一个图像作为整个对话框背景但它显示白色边框默认图像还..我添加了屏幕截图,以便您可以了解...我的代码如下:

enter image description here

我的代码是:

dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:orientation="vertical" 
      android:layout_gravity="center"   >



        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:background="@drawable/dialoguebox"
            android:padding="50dp"
                   >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Login"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <EditText
                android:id="@+id/usernm"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:background="@drawable/bg_editext"
                android:gravity="center"
                android:hint="User name" >

                <requestFocus />
            </EditText>

            <EditText
                android:id="@+id/pwd"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:background="@drawable/bg_editext"
                android:gravity="center"
                android:hint="Password"
                android:inputType="textPassword" />

            <CheckBox
                android:id="@+id/chk_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Remember me" />

            <Button
                android:id="@+id/login"
                android:layout_width="fill_parent"
                android:layout_height="32dp"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/btn_small"
                android:gravity="center"
                android:text="Login"
                android:textColor="#f6f1eb"
                android:textStyle="bold" />
        </LinearLayout>


</LinearLayout>

对话框代码

final Dialog dialog = new Dialog(Registration.this);
            // Remove title bar

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.login_dialog);

            final EditText UserName = (EditText) dialog
                    .findViewById(R.id.usernm);
            final EditText Password = (EditText) dialog
                    .findViewById(R.id.pwd);

            Button login = (Button) dialog.findViewById(R.id.login);
            login.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    // dialog.dismiss();
                    String usr = UserName.getText().toString();
                    String pwd = Password.getText().toString();
                    Intent i =new Intent(Registration.this,ProgressActivity.class);
                    startActivity(i);

                }

            });
            dialog.show();
            break;

1 个答案:

答案 0 :(得分:1)

将其添加到res / values / styles.xml

<style name="Theme.Custom" parent="android:Theme" >
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowFrame">@null</item>
       <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    </style>

这是我正在制作的自定义对话框

public class TextEditDialog extends **Dialog** implements OnClickListener {

    public TextEditDialog(Context context) {
        super(context,R.style.Theme_Custom); // ---Here I can Add this Theme
        c=context;
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
}