package liu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.example.demo_0330.R;
public class PopupWindows_Activity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindows_layout);
Button bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View view=getLayoutInflater().inflate(R.layout.popupwindows_item_layout,null);
//创建PopupWindw(窗体的视图,宽,高)
PopupWindow popupwindows=new PopupWindow(view,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
popupwindows.setTouchable(true);
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框,我觉得这里是API的一个bug,并且不设置背景会出错
popupwindows.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));
//制定动画图片
popupwindows.setAnimationStyle(android.R.style.Animation_Translucent);
popupwindows.getBackground().setAlpha(100);
popupwindows.setOutsideTouchable(true);
popupwindows.setFocusable(true);
popupwindows.setTouchable(true);
popupwindows.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//设置显示位置
popupwindows.showAsDropDown(v, Gravity.BOTTOM,0);
Button bt1=(Button) view.findViewById(R.id.button_queding);
Button bt2=(Button) view.findViewById(R.id.button_quxiao);
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopupWindows_Activity.this,"开始提交",0).show();
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopupWindows_Activity.this,"开始取消",0).show();
}
});
}
});
}
}
PopupWindows(提示框)代码详解
最新推荐文章于 2022-10-13 07:10:17 发布