轻松实现dialog弹窗

   记录一下传统的实现弹窗方式,实现一个简单的弹窗效果;

 要实现一个弹窗我们首先要创建一个类去继承dialog,主题theme需要在style文件中添加以下标签。

<style name="Dialog" parent="android:style/Theme.Dialog">
    <item name="android:background">#00000000</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
</style>    
有了这个我们就可以进行下一步:定义一个类
 
/**
 * dialog
 * Created by Administrator on 2017/8/4.
 */


public class DialogAssure extends Dialog {
    private Context context;
    private View assureView;
    ProductServiceAssureAdapter assureAdapter;
    //构造
    public DialogAssure(@NonNull Context context,List<Map<String,String>> listSafe) {
        super(context, R.style.Dialog);
        this.context=context;
        assureView= LayoutInflater.from(context).inflate(R.layout.dialog_assure_layout,null);
        setContentView(assureView);
        //noinspection ConstantConditions
        getWindow().getAttributes().gravity = Gravity.BOTTOM;
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        LinearLayoutManager layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        assureAdapter=new ProductServiceAssureAdapter(context,listSafe,2);
        recyclerView.setAdapter(assureAdapter);
    }

    @Override
    public void show() {
        Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
        @SuppressWarnings("ConstantConditions")
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = display.getWidth(); //设置宽度
        getWindow().setAttributes(lp);
        super.show();
    }
    //选择框向上弹出动画
    @Override
    protected void onStart() {
        Animation anim = AnimationUtils.loadAnimation(getContext(),R.anim.push_bottom_in);
        assureView.startAnimation(anim);
        super.onStart();
    }

}

接下来就是在你要用的地方进行实例化

     new Dialog();//这里括号里传对应于构造方法中所需要的数据


效果图如下:


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值