• cathome 猫家 开发日记-弹窗


    为什么android 和ios 的弹窗都做的灵活性不高?

    android自带的连个满宽都要自己写代码来实现。 真是无聊。

    样式

    <!--popupwindow -->
        <style name="Theme.Light.Dialog" parent="android:style/Theme.Dialog">
            <item name="android:windowBackground">@android:color/transparent</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:scrollHorizontally">true</item>
        </style>

    继承自 AppCompatDialog

    package com.utils.widgets;
    
    import android.content.Context;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatDialog;
    import android.view.Gravity;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
    
    import com.android.linson.catshome.R;
    
    public abstract class LSUIPopupWindow extends AppCompatDialog
    {
        protected int mHeight=-1;
        protected RelativeLayout mContentLayout;
        protected String mTitle="";
        protected TextView mTVTitle;
        protected LinearLayout mMenuLayout;
        protected Button mBtn_cancel;
        protected Button mBtn_submit;
        private static int mWindowStyle=R.style.Theme_Light_Dialog;
    
        public LSUIPopupWindow(Context context, int heightdp, String title)
        {
            super(context,mWindowStyle);
            mHeight=heightdp;
            mTitle=title;
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            SetupFullWindow();
            setContentView(R.layout.lsuipopupwindow);
            mContentLayout=findViewById(R.id.popupcontenct);
            mTVTitle=findViewById(R.id.popuptitle);
            mTVTitle.setText(mTitle);
            mMenuLayout=findViewById(R.id.popupmenu);
            mBtn_cancel=findViewById(R.id.btn_cancel);
            mBtn_submit=findViewById(R.id.btn_submit);
            mBtn_submit.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    OnClickSubmit(v);
                }
            });
            mBtn_cancel.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    dismiss();//windowmanager.removeview.......
                }
            });
    
            OnBaseCreated(savedInstanceState);
        }
    
        public abstract void OnClickSubmit(View v);
    
        public abstract void OnBaseCreated(Bundle savedInstanceState);
    
        private void SetupFullWindow()
        {
            Window window= getWindow();
            window.setGravity(Gravity.BOTTOM);
    
            // window.setWindowAnimations(R.style.dialogStyle);
            window.getDecorView().setPadding(0, 0, 0, 0);
    
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height =mHeight;
            window.setAttributes(lp);
        }
    }

    使用,基类做成虚类,主要目的是让派生类强制实现虚方法。其实基类非虚类更合理。不过无所谓了。

    testpopup ab =new testpopup(this,400,"hi");
            ab.show();
    public static class testpopup extends LSUIPopupWindow
        {
            public testpopup(Context context, int heightdp, String title)
            {
                super(context, heightdp, title);
            }
    
            @Override
            public void OnClickSubmit(View v)
            {
                dismiss();
            }
    
            @Override
            public void OnBaseCreated(Bundle savedInstanceState)
            {
    
            }
        }
  • 相关阅读:
    流畅的python——2 数据结构
    流畅的python——1 数据模型
    cpp3 std::bind
    cpp2 std::forward
    什么是 jQuery EasyUI?
    .Core中什么事依赖注入?
    .net 中datetime? 和 datetime 有什么区别?
    C#生成项目失败 错误列表 CS2001 未能找到源文件 “D:XXXXXX.cs”。
    Docker笔记
    ICollection与IEnumerable
  • 原文地址:https://www.cnblogs.com/lsfv/p/9831368.html
Copyright © 2020-2023  润新知