【问题标题】:Display dialog box on top right corner in android activity在android活动的右上角显示对话框
【发布时间】:2014-03-06 06:43:11
【问题描述】:

如何在android活动的右上角显示对话框。

下面是我的对话框代码

item.xml

 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="150dp"
    android:layout_height="wrap_content" >

    <com.CustomToggleButton
        android:id="@+id/toggleButton2"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:textOff="@string/off_txt"
        android:textOn="@string/on_txt" />

</TableLayout>

ActivityMy.java

 dialog_box = new Dialog(ActivityMy.this);
                        dialog_box.setContentView(R.layout.item);
                        dialog_box.show();

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    这样做 -

    Window window = dialog.getWindow();
    WindowManager.LayoutParams wlp = window.getAttributes();
    wlp.gravity = Gravity.TOP | Gravity.RIGHT;
    
    wlp.width = LayoutParams.MATCH_PARENT;
    wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    window.setAttributes(wlp);
    

    【讨论】:

      【解决方案2】:

      如果您想留出一些余量,请使用

      Window window = dialog.getWindow();
      WindowManager.LayoutParams wlp = window.getAttributes();
      wlp.gravity = Gravity.TOP | Gravity.RIGHT;
      wlp.width = LayoutParams.MATCH_PARENT;
      wlp.y=100   //if you want give margin from top
      wlp.x=100     //if you want give margin from left
      wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
      window.setAttributes(wlp);
      

      【讨论】:

        猜你喜欢
        • 2017-08-21
        • 1970-01-01
        • 1970-01-01
        • 2020-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多