import{_ as l,r as o,o as p,c as i,b as n,d as s,a as t,e as a}from"./app--CGKFO0X.js";const c={},r=a(`
This is a Hikage extension dependency for UI component-related features.
You can add this module to your project using the following method.
Add dependency in your project's gradle/libs.versions.toml.
[versions]
hikage-extension = "<version>"
[libraries]
hikage-extension = { module = "com.highcapable.hikage:hikage-extension", version.ref = "hikage-extension" }
Configure dependency in your project's build.gradle.kts.
implementation(libs.hikage.extension)
Please change <version> to the version displayed at the top of this document.
Configure dependency in your project's build.gradle.kts.
implementation("com.highcapable.hikage:hikage-extension:<version>")
Please change <version> to the version displayed at the top of this document.
Hikage provides better extensions for Activity, and creating a Hikage in Activity will be easier.
The following example
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView {
LinearLayout(
lparams = LayoutParams(matchParent = true) {
topMargin = 16.dp
},
init = {
orientation = LinearLayout.VERTICAL
gravity = Gravity.CENTER
}
) {
TextView {
text = "Hello, World!"
textSize = 16f
gravity = Gravity.CENTER
}
}
}
}
}
With the setContentView extension method of Hikage, you can set the layout using the setContent method like Jetpack Compose.
Using Hikage to create a layout in Window is consistent with Activity, you just need to use the setContentView method to pass in a Hikage layout.
If you want to create a layout using Hikage directly in AlertDialog, you can now do it more simply using the following scheme.
The following example
// Assume this is your Context.
val context: Context
// Create a dialog box and display it.
AlertDialog.Builder(context)
.setTitle("Hello, World!")
.setView {
TextView {
text = "Hello, World!"
textSize = 16f
}
}
.show()
To create a layout using Hikage in AlertDialog, you just need to use the setView method to pass in a Hikage layout.
If you inherited from Dialog for customization, you can use the setContentView method as in Activity.
The following example
class CustomDialog(context: Context) : Dialog(context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView {
LinearLayout(
lparams = LayoutParams(matchParent = true) {
topMargin = 16.dp
},
init = {
orientation = LinearLayout.VERTICAL
gravity = Gravity.CENTER
}
) {
TextView {
text = "Hello, World!"
textSize = 16f
gravity = Gravity.CENTER
}
}
}
}
}
You can inherit from PopupWindow for customization and then use Hikage to create the layout, and you can use the setContentView method like in Activity.
The following example
class CustomPopupWindow(context: Context) : PopupWindow(context) {
init {
setContentView(context) {
LinearLayout(
lparams = LayoutParams(matchParent = true) {
topMargin = 16.dp
},
init = {
orientation = LinearLayout.VERTICAL
gravity = Gravity.CENTER
}
) {
TextView {
text = "Hello, World!"
textSize = 16f
gravity = Gravity.CENTER
}
}
}
}
}
Pay Attention
To create a PopupWindow for Hikage layout, you need to use the Context constructor method to initialize it. If the Context cannot be obtained immediately, please pass the Context instance to the setContentView method.
Hikage extends the addView method of ViewGroup, and you can use the Hikage layout directly to quickly add new layouts to the current ViewGroup.
The following example
// Assume this is your ViewGroup.
val root: FrameLayout
// Add Hikage layout.
root.addView {
TextView {
text = "Hello, World!"
textSize = 16f
}
}
Or, use in a custom View.
The following example
class CustomView(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
init {
addView<FrameLayout.LayoutParams> {
TextView {
text = "Hello, World!"
textSize = 16f
}
}
}
}