自定義一個全屏的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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM