亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android超簡(jiǎn)單懸浮窗使用教程

 更新時(shí)間:2021年09月28日 10:59:03   作者:PlayfulKing  
這篇文章主要介紹了Android超簡(jiǎn)單懸浮窗使用教程,本文分步驟給大家介紹了使用前需要依賴庫(kù),給大家介紹的非常詳細(xì),需要的朋友可以參考下

完全自定義懸浮窗,保證100%學(xué)會(huì)的超簡(jiǎn)單懸浮窗

先看看效果圖:

                圖1                                                 圖2                                              圖3           

 圖1只需要31行代碼即可完成。

我們來看看這些都是如何實(shí)現(xiàn)的

 使用前需要依賴庫(kù):

第一步:將以下存儲(chǔ)庫(kù)將其添加到根構(gòu)建中。

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

第二步:添加依賴關(guān)系 build.gradle(Module:app)

(注意:當(dāng)前演示的版本號(hào)是1.3.1.3版本,今后會(huì)有新的版本發(fā)布,歡迎使用最新版)

dependencies {
        ...
	implementation 'com.github.1079374315:GSLS_Tool:v1.3.1.3'
}

依賴詳細(xì)教程:

依賴GT庫(kù)

第一步:自定義的xml布局 demo_floating_window

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
 
    <!-- ConstraintLayout 必須要將對(duì)話框大小設(shè)置出來,解決設(shè)置最外層寬高無效的問題 -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/view_bg"
        android:layout_width="300dp"
        android:layout_height="200dp"
        android:background="#5B77D5FF"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
 
        <TextView
            android:id="@+id/tv_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="×"
            android:textColor="#99FFFFFF"
            android:textSize="28sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
 
        <TextView
            android:id="@+id/tv_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#8D03B1FF"
            android:padding="10dp"
            android:text="簡(jiǎn)易自定義對(duì)話框\n支持返回?cái)?shù)據(jù)\n支持監(jiān)聽返回鍵\n用法與 Fragment 毫無差異\n"
            android:textColor="#A4FFFFFF"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/btn_ok"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_back" />
 
        <Button
            android:id="@+id/btn_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="好的"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
            app:layout_constraintStart_toStartOf="parent" />
 
        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="取消"
            app:layout_constraintBottom_toBottomOf="@+id/btn_ok"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/btn_ok" />
 
    </androidx.constraintlayout.widget.ConstraintLayout>
 
 
</LinearLayout>

第二步:加載懸浮窗布局

//加載布局
@GT.Annotations.GT_AnnotationDialogFragment(R.layout.demo_floating_window)
public class DemoFloatingWindow extends GT.GT_FloatingWindow.AnnotationFloatingWindow {
 
    @Override
    protected void initView(View view) {
        super.initView(view);
        setDrag(true);//設(shè)置可拖動(dòng)
    }
 
    @GT.Annotations.GT_Click({R.id.btn_ok, R.id.tv_back, R.id.btn_cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                GT.toast("單擊了ok");
                break;
            case R.id.tv_back:
            case R.id.btn_cancel:
                finish();
                break;
        }
    }
 
}

第三步:使用懸浮窗

//加載布局
@GT.Annotations.GT_AnnotationActivity(R.layout.activity_main)
public class MainActivity extends GT.GT_Activity.AnnotationActivity {
 
    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
 
        findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startFloatingWindow(DemoFloatingWindow.class);//啟動(dòng)懸浮窗
            }
        });
 
    }
 
}

總結(jié):熟悉GT庫(kù)的是不是感覺特別熟悉,沒錯(cuò),GT內(nèi)的Activity、Fragment、DialogFragment、FloatingWindow 的使用方法與結(jié)構(gòu)都是一模一樣的,也就是說只要你學(xué)會(huì)了其中一個(gè),那就等同于其他的你都學(xué)會(huì)了。

糖豆:如果想要圖2、圖3的源碼,請(qǐng)直接下載最新GT庫(kù),GT庫(kù)中的 util 目錄中就是源碼。 啟動(dòng)GT模擬手機(jī)版懸浮窗的代碼如下:   

點(diǎn)個(gè)關(guān)注點(diǎn)個(gè)贊唄(〃'▽'〃),關(guān)注博主最新發(fā)布庫(kù):GitHub - 1079374315/GT

到此這篇關(guān)于Android超簡(jiǎn)單懸浮窗使用教程的文章就介紹到這了,更多相關(guān)Android懸浮窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論