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

Android中PopupWindow彈出式窗口使用方法詳解

 更新時(shí)間:2022年09月19日 14:31:47   作者:路宇  
這篇文章主要為大家詳細(xì)介紹了Android中PopupWindow彈出式窗口的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android中PopupWindow彈出式窗口使用的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:

實(shí)現(xiàn)代碼如下:

activity_popup_window.xml按鈕

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context=".PopupWindowActivity">

? ? <Button
? ? ? ? android:id="@+id/btn_popupWindow"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_gravity="center"
? ? ? ? android:text="PopupWindow" />
</LinearLayout>

自定義彈出的視圖layout_pop.xml,也可以用RecycleView或者ListView

<?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:id="@+id/tv_good"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:gravity="center"
? ? ? ? android:paddingTop="8dp"
? ? ? ? android:paddingBottom="8dp"
? ? ? ? android:text="好"
? ? ? ? android:textColor="@color/gray"
? ? ? ? android:textSize="20sp" />

? ? <View
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0.5dp"
? ? ? ? android:background="@color/gray" />

? ? <TextView
? ? ? ? android:id="@+id/tv_not_too_bad"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:gravity="center"
? ? ? ? android:paddingTop="8dp"
? ? ? ? android:paddingBottom="8dp"
? ? ? ? android:text="還行"
? ? ? ? android:textColor="@color/gray"
? ? ? ? android:textSize="20sp" />

? ? <View
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0.5dp"
? ? ? ? android:background="@color/gray" />

? ? <TextView
? ? ? ? android:id="@+id/tv_bad"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:gravity="center"
? ? ? ? android:paddingTop="8dp"
? ? ? ? android:paddingBottom="8dp"
? ? ? ? android:text="不好"
? ? ? ? android:textColor="@color/gray"
? ? ? ? android:textSize="20sp" />
</LinearLayout>

PopupWindowActivity類實(shí)現(xiàn)代碼如下:

public class PopupWindowActivity extends AppCompatActivity {
? ? private Button btn_popupWindow;
? ? private PopupWindow popupWindow;

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_popup_window);
? ? ? ? btn_popupWindow = findViewById(R.id.btn_popupWindow);
? ? ? ? btn_popupWindow.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? View popup_view = LayoutInflater.from(PopupWindowActivity.this).inflate(R.layout.layout_pop, null);
? ? ? ? ? ? ? ? TextView textView = popup_view.findViewById(R.id.tv_good);
? ? ? ? ? ? ? ? textView.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? ? ? ? ? popupWindow.dismiss();
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(PopupWindowActivity.this, "好", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? popupWindow = new PopupWindow(popup_view, btn_popupWindow.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
? ? ? ? ? ? ? ? //設(shè)置彈出窗口應(yīng)該接收外部觸摸事件
? ? ? ? ? ? ? ? popupWindow.setOutsideTouchable(true);
? ? ? ? ? ? ? ? //設(shè)置可聚焦
? ? ? ? ? ? ? ? popupWindow.setFocusable(true);
? ? ? ? ? ? ? ? popupWindow.showAsDropDown(btn_popupWindow);
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

以上就是PopupWindow彈出式窗口的簡(jiǎn)單使用。

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

相關(guān)文章

最新評(píng)論

兴安盟| 双柏县| 中宁县| 松桃| 井冈山市| 遵化市| 石林| 德保县| 西和县| 红桥区| 石泉县| 那坡县| 宁波市| 长武县| 隆子县| 桐乡市| 义马市| 报价| 博罗县| 新蔡县| 霞浦县| 清苑县| 平罗县| 绿春县| 大洼县| 普安县| 太谷县| 远安县| 齐齐哈尔市| 富阳市| 张家界市| 建阳市| 海口市| 敦煌市| 远安县| 射洪县| 伽师县| 永新县| 江陵县| 梅州市| 兴仁县|