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;
}
}到此這篇關(guān)于android WindowManager的簡單使用的文章就介紹到這了,更多相關(guān)android WindowManager使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
android開發(fā)socket編程之udp發(fā)送實例分析
這篇文章主要介紹了android開發(fā)socket編程之udp發(fā)送,實例分析了Android開發(fā)socket網(wǎng)絡(luò)編程中udp發(fā)送的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
Android 實現(xiàn)ListView的點擊變色的實例
這篇文章主要介紹了Android 實現(xiàn)ListView的點擊變色的實例的相關(guān)資料,主要實現(xiàn)Android listveiw ItemClickListener寫入變色的功能,需要的朋友可以參考下2017-07-07
Android實現(xiàn)的可以調(diào)整透明度的圖片查看器實例
這篇文章主要介紹了Android實現(xiàn)的可以調(diào)整透明度的圖片查看器,需要的朋友可以參考下2014-07-07
百度地圖API提示230 錯誤app scode碼校驗失敗的解決辦法
筆者近2天在 Android Studio上玩了一下百度地圖,碰到了常見的"230錯誤 APP Scode校驗失敗",下面我來介紹一下具體的解決辦法2016-01-01
超簡單Android集成華為HMS Scankit 掃碼SDK實現(xiàn)掃一掃二維碼
這篇文章主要介紹了超簡單Android集成華為HMS Scankit 掃碼SDK實現(xiàn)掃一掃二維碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03
Android小程序?qū)崿F(xiàn)訪問聯(lián)系人
這篇文章主要為大家詳細介紹了Android小程序?qū)崿F(xiàn)訪問聯(lián)系人,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一2020-05-05

