hikage-extension
This is a Hikage extension dependency for UI component-related features.
Configure Dependency
You can add this module to your project using the following method.
SweetDependency (Recommended)
Add dependency in your project's SweetDependency
configuration file.
libraries:
com.highcapable.hikage:
hikage-extension:
version: +
Configure dependency in your project build.gradle.kts
.
implementation(com.highcapable.hikage.hikage.extension)
Traditional Method
Configure dependency in your project build.gradle.kts
.
implementation("com.highcapable.hikage:hikage-extension:<version>")
Please change <version>
to the version displayed at the top of this document.
Function Introduction
You can view the KDoc click here.
Activity
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.
Window
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.
Dialog
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
}
}
}
}
}
PopupWindow
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.
ViewGroup
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 {
TextView {
text = "Hello, World!"
textSize = 16f
}
}
}
}