android WindowManager的简单使用实例详解

 更新时间:2023年08月31日 08:34:33   作者:玲珑·  
这篇文章主要介绍了android WindowManager的简单使用,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

android WindowManager的简单使用

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.App0"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
package com.koala.app0;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
    private static Context context;
    private Button button;
    private View imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = getApplication().getApplicationContext();
        button = findViewById(R.id.btn1);
        imageView = LayoutInflater.from(context).inflate(R.layout.png,null);
        button.setOnClickListener(listener);
    }
    private View.OnClickListener listener =  new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
//            layoutParams.format = PixelFormat.RGBA_8888;
            layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
//            layoutParams.width = 200;
//            layoutParams.height = 200;
//            layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
//            layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
            layoutParams.x = 30;
            layoutParams.y = 40;
            WindowManager windowManager = getWindowManager();
            windowManager.addView(imageView,layoutParams);
        }
    };
    public static Context getContext(){
        return context;
    }
}

到此这篇关于android WindowManager的简单使用的文章就介绍到这了,更多相关android WindowManager使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • android图片圆角、图片去色处理示例

    android图片圆角、图片去色处理示例

    这篇文章主要介绍了android图片圆角、图片去色处理示例,需要的朋友可以参考下
    2014-05-05
  • Android对话框使用方法详解

    Android对话框使用方法详解

    这篇文章主要介绍了Android对话框使用方法,包括提示对话框、单选对话框、复选对话框、列表对话框等,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-09-09
  • 安卓(Android)聊天机器人实现代码分享

    安卓(Android)聊天机器人实现代码分享

    这是一个安卓智能聊天机器人的源码,采用了仿微信的风格设计,调用的是图灵机器人的API,能够实现智能聊天、讲故事、讲笑话、查天气、查公交等丰富的功能
    2015-11-11
  • Android 模拟新闻APP显示界面滑动优化实例代码

    Android 模拟新闻APP显示界面滑动优化实例代码

    所谓滑动优化就是滑动时不加载图片,停止才加载,第一次进入时手动加载。下面通过本文给大家介绍android 模拟新闻app显示界面滑动优化实例代码,需要的朋友可以参考下
    2017-03-03
  • Android监听电池状态实例代码

    Android监听电池状态实例代码

    这篇文章给大家介绍Android监听电池状态实例代码,对android监听电池状态相关知识感兴趣的朋友一起学习吧
    2016-03-03
  • 浅谈Android Studio 3.0 的一些小变化

    浅谈Android Studio 3.0 的一些小变化

    本篇文章主要介绍了浅谈Android Studio 3.0 的一些小变化,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-10-10
  • Android录音功能的实现以及踩坑实战记录

    Android录音功能的实现以及踩坑实战记录

    在Android 开发过程中,有些功能是通用的,或者是多个业务方都需要使用的,下面这篇文章主要给大家介绍了关于Android录音功能的实现以及踩坑的相关资料,需要的朋友可以参考下
    2022-06-06
  • android2.3.5 CDMA/EVDO拨号APN解决方案

    android2.3.5 CDMA/EVDO拨号APN解决方案

    google提供的android2.3里面,只能在GSM/WCDMA情况下才能从“设置”->“无线和网络”->“移动网络”->“接入点名称”中选择不同的apn帐号进行拨号连接,而CDMA/EVDO则没有这个功能,接下来本文介绍一些方法实现这个功能,感兴趣的朋友可以了解下
    2013-01-01
  • Android的进度条控件描述

    Android的进度条控件描述

    这篇文章主要介绍了android的几种进度条控件描述的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-01-01
  • Android studio 三大模拟器比较(图文详解)

    Android studio 三大模拟器比较(图文详解)

    这篇文章主要介绍了Android studio 三大模拟器比较,本文图文并茂给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03

最新评论