Android开发之旅一PopupWindow写的一个基类和PopupWindow中EditText输入法的问题

呵呵,几乎看遍了,才找到解决的方法,看看下面的代码




import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.mobile.consumer.R;

/**
 * 
 * @author joke
 * 
 * panel类
 *
 */
public class Pop {
	
	private PopupWindow pop; //弹出窗口
	private View parentView; //窗口依赖的父类view
	private Activity mContext;
	
	public Pop(Activity context,View pView) {
		// TODO Auto-generated constructor stub
		
		this.mContext=context;
		this.parentView=pView;
		
	}
	
	//创建一个panel
	public void init(View view){
		pop=new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT,false);
		
		pop.setFocusable(true);
		pop.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
		pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		
		ColorDrawable dw = new ColorDrawable(Color.parseColor("#cccccc"));
		pop.setBackgroundDrawable(dw);
		pop.setAnimationStyle(R.style.panel);
		pop.showAtLocation(parentView, Gravity.BOTTOM, 0,0);
		
		
	}
	
	//关闭
	public void close(){
		if(null != pop){
			pop.dismiss();
		}
	}

}

测试例子



import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;


import com.mobile.pop.Pop;

public class test extends Pop{

	public test(Activity context, View pView) {
		super(context, pView);
		// TODO Auto-generated constructor stub
		
		View view=LayoutInflater.from(mContext).inflate(R.layout.mysize_add_activity, null);
		
		init(view);
	}


}


打完下班了,哈哈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的示例代码: 首先,在你的布局文件定义一个按钮,点击该按钮将会弹出提示框: ```xml <Button android:id="@+id/btn_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除冗余文件" android:onClick="showPopup"/> ``` 接下来,在你的Activity实现showPopup()方法: ```java public void showPopup(View view) { // 创建一个PopupWindow对象 PopupWindow popupWindow = new PopupWindow(this); // 设置PopupWindow的宽度和高度 popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置PopupWindow的内容视图 View contentView = LayoutInflater.from(this).inflate(R.layout.popup_layout, null); popupWindow.setContentView(contentView); // 设置PopupWindow的焦点,使其能够响应点击事件 popupWindow.setFocusable(true); // 设置PopupWindow的背景,这样点击PopupWindow外部的空白区域,就能够自动关闭PopupWindow popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // 设置PopupWindow的动画 popupWindow.setAnimationStyle(R.style.PopupAnimation); // 显示PopupWindow popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0); } ``` 在上面的代码,我们首先创建了一个PopupWindow对象,然后设置了它的宽度和高度,并且将布局文件popup_layout.xml设置为其内容视图。接着,我们设置了PopupWindow的焦点和背景,使其能够响应点击事件,并且在点击空白区域时自动关闭。最后,我们设置了PopupWindow的动画,并且调用showAtLocation()方法将其显示在屏幕的央位置。 最后,你需要创建popup_layout.xml布局文件,这个布局文件可以自定义,用来展示你要提示用户的信息。例如,以下是一个简单的示例布局文件: ```xml <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="#FFFFFF" android:padding="16dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="是否删除冗余文件?" android:textSize="18sp" android:textColor="#000000"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="16dp"> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" android:textColor="#000000" android:background="#EEEEEE" android:layout_weight="1"/> <Button android:id="@+id/btn_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:textColor="#FFFFFF" android:background="#FF4081" android:layout_weight="1"/> </LinearLayout> </LinearLayout> ``` 在这个布局文件,我们使用了一个垂直方向的LinearLayout来包含一个TextView和一个水平方向的LinearLayout,水平方向的LinearLayout包含了“取消”和“确定”两个Button按钮。 现在你就可以通过点击“删除冗余文件”按钮,弹出提示框,询问用户是否进行冗余文件的删除了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值