Android弹窗
16lz
2021-01-23
<span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8"?></span>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/ic_launcher" android:orientation="vertical" > <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /></LinearLayout>
package com.example.popupwindow_demo;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.widget.Button;import android.widget.PopupWindow;import android.widget.TextView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final Activity activity=this;finalButton button=(Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {LayoutInflater mLayoutInflater=activity.getLayoutInflater();View view=mLayoutInflater.inflate(R.layout.myview, null);TextView text=(TextView) view.findViewById(R.id.textView);text.setText("hello,world!");PopupWindow popupWindow=new PopupWindow(view,300,720);popupWindow.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.alert_dark_frame));popupWindow.setOutsideTouchable(true);//popupWindow.showAsDropDown(button);popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);}});}}
更多相关文章
- Android手机操作系统中实现图片浏览
- Android 利用Matrix实现图片随手指平移、旋转、缩放
- 巧用Android图片资源,打造更精致的APP
- Android 实现图片保存到本地并调用本地地址显示图片
- Android设置拍照或者上传本地图片
- android 工程,点击图片,在屏幕显示
- Android ListView(Selector 背景图片)
- android基础:动画案例(图片翻转)