Android - popWindow简单使用

效果

点击控件,弹出窗口;再次点击控件,窗口消失;
点击按钮一,吐丝,窗口消失;
点击按钮二、三,吐丝,窗口不消失;
点击外部,窗口消失;

在这里插入图片描述效果

在这里插入图片描述

设置多一个布局 - - 窗口的布局
相关代码解释,在注释里有写

activity_main.xml

 <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textSize="25dp"
       android:text="popWindow"
       android:padding="10dp"
       android:id="@+id/tv_popWindow"/>

activity_popwindow.xml

   <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="按钮一"
        android:id="@+id/bt_one"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="按钮二"
        android:id="@+id/bt_two"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="按钮三"
        android:id="@+id/bt_three"/>

在这里插入图片描述

MainActivity.java

//控件,点击弹出窗口
 tv = findViewById(R.id.tv_popWindow);
        tv.setOnClickListener(new View.OnClickListener() {
   
            @Override
            public void onClick(View v) {
   
            	//窗口
                popWindo
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值