Coder Social home page Coder Social logo

cybkw / fitsystembarutils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matcha-xiaobin/fitsystembarutils

0.0 0.0 0.0 7.09 MB

沉浸式状态栏,一个自动处理WindowInsets和cutOut的工具,一行代码 给任意view绑定。 你还在苦恼布局中背景图需要上到状态栏或者虚拟导航键下面,却写不好其他控件的布局吗? 你还在获取状态栏高度的方式去给布局设置一个paddingTop吗? 快来试试看这个吧。 功能非常简单,没几行代码。 可以实现软键盘弹起时,平滑的推起底部的输入框哦!(比微信还丝滑)

Kotlin 100.00%

fitsystembarutils's Introduction

FitSystemBarUtils

沉浸式状态栏,一个自动处理WindowInsets和cutOut的工具,一行代码 给任意view绑定。 你还在苦恼布局中背景图需要上到状态栏或者虚拟导航键下面,却写不好其他控件的布局吗? 你还在获取状态栏高度的方式去给布局设置一个paddingTop吗? 快来试试看这个吧。 功能非常简单,没几行代码。

可以实现软键盘弹起时,平滑的推起底部的输入框哦!(比微信还丝滑)

Demo录屏gif:

在项目中引用

Gradle

Step 1. Add it in your root build.gradle at the end of repositories

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

Step 2. Add the dependency

dependencies {
    implementation 'com.github.Matcha-xiaobin:fitSystemBarUtils:1.0.3'
}

目前BUG:

突然发现在Android 10系统上出现了系统栏明明隐藏了,高度却没有变成0的问题,android 11+似乎没问题。 目前已修复,并且禁用了低于android 11的动画效果,实际上ViewCompat中帮我们实现了低于android 11的设备的动画效果,但是存在问题。

在代码中使用:

这个工具本质是把系统分发的insets属性拿出来用了一下,可以参考下google的 BottomNavigationView 底部导航 的代码,里面也用到了这个原理。 注意:如果你不知道这个时干啥用的,建议下载demo看看实际效果是不是你需要的效果

任意View实现FitSystemBar效果 中间内容区域上下两边不需要填充,因为上面有标题栏,下面有输入框栏

FitSystemBarHelper.attachView(
    binding.content,
    start = true,
    top = false,
    end = true,
    bottom = false
)
//第二种写法, 这种写法支持动态改变,但改变后的生效时间由系统分发WindowInsets的时机决定
//如果需要立即生效,请在改变值后调用 fitSystemHelperForContent.requestApplyInsets()
FitSystemBarHelper.attachView(binding.content) { orientation ->
    when (orientation) {
        FitSystemBarHelper.Orientation.Start -> true
        FitSystemBarHelper.Orientation.Top -> false
        FitSystemBarHelper.Orientation.End -> true
        FitSystemBarHelper.Orientation.Bottom -> false
    }
}

获取这个View已绑定的FitSystemBarHelper对象

view.fitSystemBarHelper()

取消绑定

view.fitSystemBarHelper()?.destory()

使用DataBinding在xml中使用

每个属性的默认值为false 是否处理Start方向的

fitStart="@{true}" 

是否处理上方的

fitTop="@{true}" 

是否处理End方向的

fitEnd="@{true}" 

是否处理下方的

fitBottom="@{true}" 

自定义View

自带了3个: FitNavigationBarFrameLayout 用作根布局最底下的不需要处理顶部状态栏区域的填充的 FrameLayout FitNavigationBarLinearLayout 用作根布局最底下的不需要处理顶部状态栏区域的填充的 LinearLayout FitStatusBarLinearLayout 用作根布局最上方的不需要处理底部导航栏区域的填充的 LinearLayout 直接参考即可,甚至可以直接拷贝一模一样,将继承的目标换成你需要的View即可

fitsystembarutils's People

Contributors

matcha-xiaobin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.