Android:没有阴影的对话框

时间:2011-01-21 10:12:55

标签: android alertdialog

如何在淡化背景的对话框周围删除此“shadowBox”效果?

我知道我可以创建完全自定义的视图,但是我想说我想保持简单。我有对话框的xml布局,只有textView和2个按钮,我想只为这一个对话框停止淡入淡出。

5 个答案:

答案 0 :(得分:36)

尝试:

dialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);

答案 1 :(得分:7)

style.xml内创建values并输入以下内容:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="progress_dialog">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:background">#00ffffff</item> 
</style>

最后,将此样式放在对话框中。

答案 2 :(得分:5)

只需使用

 dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

答案 3 :(得分:2)

这里给出样本类

public void showDialog () {

    Dialog dialog = new Dialog(this);
    Window window = dialog.getWindow();
    window.setBackgroundDrawableResource(android.R.color.transparent);
    window.requestFeature(window.FEATURE_NO_TITLE);

    dialog.setContentView(R.layout.sample);
    ImageView imggameover, imgplayagain;
    imggameover = (ImageView) dialog.findViewById(R.id.gameover);
    imgplayagain = (ImageView) dialog.findViewById(R.id.playagain);
    imgplayagain.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(getApplicationContext(), random.class));
            onStop();
            finish();
        }
    });
    dialog.show();
}

对话框的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gameoverlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"
    >
    <ImageView
        android:id="@+id/gameover"
        android:layout_width="225dip"
        android:layout_height="160dip"
        android:background="@drawable/gameover"
        ></ImageView>
    <ImageView
        android:id="@+id/playagain"
        android:layout_width="160dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dip"
        android:layout_marginTop="100dip"
        android:background="@drawable/playagain"
        ></ImageView>
</RelativeLayout>

答案 4 :(得分:0)

只是你知道也可以通过在主题中写下来改变昏暗的数量:

    private BluetoothDevice device;
    private BluetoothSocket socket;
    private OutputStream outputStream;


    String command;//string variable that will store value to be transmitted to the bluetooth module

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button BtSend = findViewById(R.id.BtSend);
        Button BtVerbinden = findViewById(R.id.BtVerbinden);
        final EditText EtEingabe = findViewById(R.id.EtEingabe);
        BtSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                command = EtEingabe.getText().toString();
                try {
                    outputStream.write(command.getBytes());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        });


        //Button that connects the device to the bluetooth module when pressed
        BtVerbinden.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (BTinit()) {
                    BTconnect();
                }

            }
        });
    }

    public boolean BTinit() {
        boolean found = false;

        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if (bluetoothAdapter == null) //Checks if the device supports bluetooth
        {
            Toast.makeText(getApplicationContext(), "Device doesn't support bluetooth", Toast.LENGTH_SHORT).show();
        }

        if (!bluetoothAdapter.isEnabled())
        {
            Intent enableAdapter = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableAdapter, 0);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();

        if (bondedDevices.isEmpty())
        {
            Toast.makeText(getApplicationContext(), "Please pair the device first", Toast.LENGTH_SHORT).show();
        } else {
            for (BluetoothDevice iterator : bondedDevices) {
                if (iterator.getAddress().equals(DEVICE_ADDRESS)) {
                    device = iterator;
                    found = true;
                    break;
                }
            }
        }

        return found;
    }

    public boolean BTconnect() {
        boolean connected = true;

        try {
            socket = device.createRfcommSocketToServiceRecord(PORT_UUID); //Creates a socket to handle the outgoing connection
            socket.connect();

            Toast.makeText(getApplicationContext(),
                    "Connection to bluetooth device successful", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
            connected = false;
        }

        if (connected) {
            try {
                outputStream = socket.getOutputStream(); //gets the output stream of the socket
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (outputStream == null) {
            try {
                outputStream = socket.getOutputStream();
            } catch (IOException e) {
            }
        }
        return connected;
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

}