線上直播系統原始碼,平臺彈窗自適應裝置

zhibo系統開發發表於2021-12-02

線上直播系統原始碼,平臺彈窗自適應裝置實現的相關程式碼

new 一個Java類 PermissionDialog extends Dialog

java 程式碼

public class PermissionDialog extends Dialog {
    private Context mContext;
    private TextView tv_title;
    private TextView tv_message;
    private Button btnLeft;
    private Button btnRight;
    private OnClickCallbackListener onClickCallbackListener;
    public PermissionDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }
    public void setOnClickCallbackListener(OnClickCallbackListener listener) {
        onClickCallbackListener = listener;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_permission);
        //獲取螢幕寬高
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int width = display.getWidth();
        //設定彈窗大小
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        //將對話方塊的大小按螢幕大小的百分比設定
//        lp.width = (int)(width*0.8); // 寬度
        lp.width = width; // 寬度
        dialogWindow.setAttributes(lp);
        //點選外面不消失
        setCancelable(false);
        tv_title = findViewById(R.id.tv_title);
        tv_message = findViewById(R.id.tv_message);
        tv_title.setText( R.string.permission_apply );
        tv_message.setText( R.string.permission_content );
        btnLeft = findViewById(R.id.btn_left);
        btnRight = findViewById(R.id.btn_rigth);
        btnLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickCallbackListener != null) {
                    onClickCallbackListener.onClickLeftBtn();
                }
                dismiss();
            }
        });
        btnRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickCallbackListener != null) {
                    onClickCallbackListener.onClickRightBtn();
                }
                dismiss();
            }
        });
    }
    public interface OnClickCallbackListener {
        void onClickLeftBtn();  //取消按鈕
        void onClickRightBtn();  //確定按鈕
    }
}
xml檔案
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_white_rectangle_6dp"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/margin_size_24dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/tv_title"
            style="@style/TextViewSize16Black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_size_16dp"
            android:textStyle="bold"
            android:text="標題名稱"/>
        <TextView
            android:id="@+id/tv_message"
            style="@style/TextViewSize14Black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingExtra="@dimen/margin_size_6dp"
            android:text="標題名稱標題"/>
        <RelativeLayout
            android:id="@+id/rl_button_layout_two"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_size_30dp"
            android:visibility="visible">
            <Button
                style="@style/TextViewSize14MainColor"
                android:id="@+id/btn_left"
                android:layout_width="@dimen/view_size_130dp"
                android:layout_height="@dimen/view_size_40dp"
                android:textSize="@dimen/text_size_14sp"
                android:textAllCaps="false"
                android:text="@string/no"
                android:background="@drawable/bg_white_round_corner_6dp20"
                android:layout_alignParentLeft="true"/>
            <Button
                style="@style/TextViewSize14White"
                android:id="@+id/btn_rigth"
                android:layout_width="@dimen/view_size_130dp"
                android:layout_height="@dimen/view_size_40dp"
                android:background="@drawable/bg_round_corner_6dp"
                android:textSize="@dimen/text_size_14sp"
                android:textAllCaps="false"
                android:text="@string/yes"
                android:layout_alignParentRight="true"/>
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

哪裡用程式碼考過去就行

 final PermissionDialog dialog = new PermissionDialog( this, R.style.Theme_AppCompat_Dialog );
                dialog.setOnClickCallbackListener( new PermissionDialog.OnClickCallbackListener( ) {
                    @Override
                    public void onClickLeftBtn() {
                        PreferencesUtils.saveLong( AppConstants.SP_SAVE_FILE_NAME, "onetime", LoginActivity.onetime );
                        dialog.cancel( );
                    }
                    @Override
                    public void onClickRightBtn() {
                        PreferencesUtils.saveLong( AppConstants.SP_SAVE_FILE_NAME, "onetime", LoginActivity.onetime );
                        doPermission( );
                    }
                } );
                dialog.show( );

以上就是 線上直播系統原始碼,平臺彈窗自適應裝置實現的相關程式碼,更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2845381/,如需轉載,請註明出處,否則將追究法律責任。

相關文章