Skip to content

BetterAndroid/Hikage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

276 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hikage

GitHub license Telegram QQ

LOGO

A real-time Android View runtime powered by Kotlin DSL.

English | 简体中文

LOGO BetterAndroid

This project belongs to the organization above. Click the link to follow us and discover more awesome projects.

What's this

Hikage (Pronunciation /ˈhɪkɑːɡeɪ/), this is an Android View runtime powered by Kotlin DSL, designed around real-time code-based UI construction.

The project icon was designed by MaiTungTM, the name is taken from the original song "Haruhikage" in "BanG Dream It's MyGO!!!!!".

Why...
LOGO

なんで春日影レイアウトしたの?

Its second layer of meaning is "Shadow under the Sun", which symbolizes the design philosophy of this framework: Hikage is like a shadow, providing a more modern and efficient UI construction system without interfering with the developer's original habits and project structure.

Hikage is focused on the native Android View ecosystem. It brings the Kotlin DSL-driven layout experience into the classic View framework, allowing you to build layouts at high speed with 100% out-of-the-box support for legacy and standard native components.

Hikage does not produce UI components, it is just a transporter of the Android 17-year-old native view ecosystem.

Why Hikage?

Hikage is mainly intended for developers focused on the native Android platform. Since Kotlin became the primary development language, there still has not been a truly complete solution for dynamic code-based layouts. Projects that do not use Jetpack Compose still have to rely on XML, and even with ViewBinding, the experience is still not especially friendly.

Hikage keeps the native Android View naming style, while drawing inspiration from Anko, Splitties, and the Jetpack Compose DSL design philosophy. This makes it feel close to native Android while still offering a modern Kotlin DSL authoring experience.

The following example

LinearLayout(
    lparams = LayoutParams(matchParent = true) {
        topMargin = 16.dp
    },
    init = {
        orientation = LinearLayout.VERTICAL
        gravity = Gravity.CENTER
    }
) {
    TextView {
        text = "Hello, World!"
        textSize = 16f
        gravity = Gravity.CENTER
    }
}

Hikage can be plug-and-play and create a View anywhere that can be attached to a parent layout or even a Window.

It is also fully compatible with hybrid layouts. You can embed XML (loaded via the R.layout scheme), ViewBinding, and even Jetpack Compose inside Hikage.

The following example

LinearLayout(
    lparams = LayoutParams(matchParent = true),
    init = {
        orientation = LinearLayout.VERTICAL
    }
) {
    // Embed an XML layout.
    Layout(R.layout.my_layout)

    // Embed a ViewBinding layout.
    Layout<MyLayoutBinding>()

    // Embed a Jetpack Compose layout.
    ComposeView {
        Text("Hello, World!")
    }
}

Compared to pure DSL scaffolding lightweight dependency libraries like Anko and Splitties, Hikage's ecosystem naturally supports dynamically constructing an AttributeSet. This solution has passed interactive tests and benchmark performance stress tests on emulators and real devices, ensuring stable compatibility with Android 5.0.2 (API 21) ~ 17 (API 37). This empowers legacy custom views that lack programmatic setters to be revitalized via Hikage.

The following example

TextView(
    attrs = {
        android {
            // The following is equivalent to android:text="Set text in dynamic AttributeSet".
            set("text", "Set text in dynamic AttributeSet")
            set("textSize", "16sp")
            set("gravity", "center")
            set("paddingLeft", "8dp")
            // Supports dynamic type conversion.
            set("paddingRight", 8.dp)
        }
    }
) {
    text = "Overridden text in code"
}

Furthermore, Hikage natively supports Android Studio's layout preview feature, allowing you to preview layout effects directly in the IDE without running the app.

From now on, forget about XML, ViewBinding, and even findViewById, and try building layouts directly in code.

Don't know Jetpack Compose? No problem. Hikage can be your Kotlin DSL version of XML today, bringing the static XML layout experience into runtime and letting you build native Android Views with Kotlin.

Hikage works best when used in conjunction with our other project BetterAndroid, and Hikage itself will automatically reference its ui-extension as a core dependency.

Get Started

LOGO Hikage Documentation

You can go to the documentation page for more detailed tutorials and content.

What's next?

  1. Add dependencies: Add the hikage-core dependency and the dependencies you need to your project.
  2. Sync the project: After a Gradle sync, you can start using Hikage.

In the opened page, select the Quick Start section in the sidebar to continue reading.

More Projects

Hey, wait a second! 👋

If this project was helpful, why not stick around and check out more of my work below?

Feel free to leave a follow or a star ⭐️ if they bring you value!

Star History

Star History Chart

Third-Party Open Source Usage Statement

License

Apache License Version 2.0

Copyright (C) 2019 HighCapable

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright © 2019 HighCapable

About

A real-time Android View runtime powered by Kotlin DSL.

Topics

Resources

License

Stars

83 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors