自訂一個全屏的AlertDialog。,全屏alertdialog

來源:互聯網
上載者:User

自訂一個全屏的AlertDialog。,全屏alertdialog

 

 

...........

final MyDialog dialog = new MyDialog(this);        LayoutInflater inflater = getLayoutInflater();        LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.layout, null);        CautionTv = (TextView) layout.findViewById(R.id.ion_tv);        ContentTv = (TextView) layout.findViewById(R.id.ntent_tv);        LanguageTv = (TextView) layout.findViewById(R.id.guage_tv);        OkBt = (Button) layout.findViewById(R.id._ok_bt);        OkBt.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                if (dialog != null) {                    dialog.cancel();                }            }        });        dialog.show();        dialog.setCancelable(false);        dialog.setContentView(layout);// show方法要在前面

 

 

 

 

 

import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.os.Bundle;import android.view.Gravity;import android.view.WindowManager;import android.view.ViewGroup.LayoutParams;import com.android.launcher.R;/** * 自訂彈框 * @author xiebin * */public class MyDialog extends AlertDialog {    Context mContext;    public MyDialog(Context context) {        super(context, R.style.MyDialog); // 自訂全屏style        this.mContext=context;    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }        @Override    public void show() {        super.show();        /**         * 設定寬度全屏,要設定在show的後面         */        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();        layoutParams.gravity=Gravity.BOTTOM;        layoutParams.width= LayoutParams.MATCH_PARENT;        layoutParams.height= LayoutParams.MATCH_PARENT;        getWindow().getDecorView().setPadding(0, 0, 0, 0);        getWindow().setAttributes(layoutParams);    }}

 

 

/Launcher/res/values/styles.xml

<!-- 全屏style -->    <style name="MyDialog" parent="@android:style/Theme.NoTitleBar.Fullscreen">        <!-- 是否有邊框 -->        <item name="android:windowFrame">@null</item>        <!--是否在懸浮Activity之上  -->        <item name="android:windowIsFloating">true</item>        <!--標題  -->        <item name="android:windowNoTitle">true</item>        <!--陰影  -->        <item name="android:windowIsTranslucent">true</item><!--半透明-->        <!-- 點外邊可以消失  -->        <item name="android:windowCloseOnTouchOutside">false</item>    </style>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.