最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android studio實(shí)現(xiàn)PopupWindow彈出框效果

 更新時(shí)間:2021年10月20日 11:52:59   作者:Be your bubble  
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)PopupWindow彈出框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android studio實(shí)現(xiàn)PopupWindow彈出框的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)步驟:

第一步:自定義.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="提示"
        android:background="@drawable/click"
        android:textSize="28sp"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center"
        android:text="你真的要離開嗎"
        android:textColor="#ff0400"
        android:background="@drawable/background"
        android:textSize="28sp"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50sp"
        android:orientation="horizontal"
        android:background="@drawable/bb"
        android:gravity="center">
        <Button
            android:id="@+id/but"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="殘忍離開"
            android:textSize="24sp"/>
    </LinearLayout>

</LinearLayout>

第二步:獲取layoutInflater對(duì)象
第三步:調(diào)用inflater()方法獲取View對(duì)象
第四步:創(chuàng)建PopupWindow對(duì)象
第五步:調(diào)用PopupWindow的showAsDropDown或者showAsLocation方法顯示對(duì)話框窗口

下拉式

默認(rèn)xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="對(duì)話框"
        android:onClick="onclick"/>
</LinearLayout>

java:

package com.example.catalogin;

import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main2);
    }

    PopupWindow popupWindow;
    public void  onclick(View v1){
        LayoutInflater inflater=LayoutInflater.from( this );
        View myview=inflater.inflate(R.layout.catalogin,null);//引用自定義布局
        popupWindow=new PopupWindow( myview,600,500 );//后面是像素大小

        myview.findViewById(R.id.but).setOnClickListener( new View.OnClickListener() {//獲取布局里面按鈕
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();//點(diǎn)擊按鈕對(duì)話框消失
                Toast.makeText( Main2Activity.this, "點(diǎn)擊了殘忍離開", Toast.LENGTH_SHORT ).show();
            }
        } );
        popupWindow.showAsDropDown(v1);
    }
}

彈出式

代碼popupWindow.showAsDropDown(v1);
換成popupWindow.showAtLocation( v1,Gravity.CENTER,0,0 );//偏移量

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

日土县| 寿阳县| 通山县| 金山区| 安宁市| 兰州市| 南京市| 蒙自县| 苏尼特左旗| 三都| 潢川县| 疏勒县| 平阴县| 万载县| 武宁县| 双辽市| 文安县| 土默特右旗| 修文县| 兴义市| 阳信县| 德庆县| 兴山县| 长葛市| 武汉市| 策勒县| 上林县| 新乡县| 永泰县| 广汉市| 翼城县| 湖北省| 边坝县| 桃源县| 梅河口市| 拜城县| 西丰县| 乐陵市| 南宫市| 嘉兴市| 海南省|