<Button
android:id=“@+id/bn”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“游览该网页”
/>
布局页面如下:
1.首先应该在AndroidManifest.xml中添加处理权限
2.创建一个WindowManager,获得权限之后,就会在屏幕正中间显示一个Button了
final WindowManager windowmanager= (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams wmParams=new WindowManager.LayoutParams();
wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION; // 设置window type
wmParams.gravity = Gravity.RIGHT| Gravity. CENTER_VERTICAL; // 调整悬浮窗口至右侧中间
wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
wmParams.height =WindowManager.LayoutParams.WRAP_CONTENT;
final Button button=new Button(getApplicationContext());
windowmanager.addView(button,wmParams);
3.接着设置这个Button的功能,一旦按下这个button,即对当前页面进行截屏
Environment.getExternalStorageDirectory()用于获取外部设备的路径,即安卓手机的SD卡(虽然现在SD卡不是很常见了)
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BitmapDrawable bd = new BitmapDr