A customisable button kit for Android
ButtonsKt eliminates boilterplate xml files through ease of customization by exposing button customizations (icons, borders & outlines, corner radius, background and more!) whilst being lightweight, plus runtime xml selection of icons from FontAwesome.
- Corner Radius
- Border (width, color)
- Layout (padding, margin)
- Easy Ripple Effect Integration (defaultBackgroundColor, focusedBackgroundColor, disabledBackgroundColor)
- Support for SDK below API Lollipop (StateListDrawable instead of RippleDrawable)
- Choose from your resource directory
- Choose from FontAwesome Icons (ttf based, not images!)
- Tint (enabledColor & disabledColor)
- Layout (iconArea, iconMargin, iconPadding)
- Choose font your resource directory
- Choose from the available fonts (eg. OpenSans, Gilroy, ...)
- Style (size, alignment, gravity, style, isTextAllCaps)
- Color (textColor, disabledTextColor)
- isEnabled
- isRippleEffectEnabled
For more info, refer to DOCS
Based on Google's Android Material Design
- Icon
- Text
- Background
- Border (Outline)
- Ripple Effect
// Project level build.gradle
// ...
repositories {
maven { url 'https://jitpack.io' }
}
// ...
// Module level build.gradle
dependencies {
// Important, be sure to explicitly declare the latest version of kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:[KOTLIN_VERSION]
// Replace version with release version, e.g. 1.0.0-alpha, -SNAPSHOT
implementation "io.jmdg:buttonskt:[VERSION]"
}
TIP: Load URI xmlns:app="http://schemas.android.com/apk/res-auto" to render runtime custom attributes
<RootLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto"
...
/>
<io.jmdg.buttonskt.ButtonsKtView
android:id="@+id/bkt_demo_xml_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="center"
...
app:bkt_isEnabled="false"
app:bkt_isRippleEffectEnabled="true"
app:bkt_cornerRadius="10dp"
app:bkt_borderWidth="2dp"
app:bkt_defaultBackgroundColor="@color/colorPrimary"
app:bkt_focusedBackgroundColor="@color/colorPrimaryDark"
app:bkt_focusedBackgroundColor="@color/colorPrimaryDisabled"
app:bkt_text="ButtonsKt"
app:bkt_textSize="12dp"
app:bkt_textStyle="normal"
app:bkt_textAllCaps="false"
app:bkt_defaultFont="opensans_light"
app:bkt_textColor="@android:color/white"
app:bkt_disabledTextColor="@android:color/darker_gray"
app:bkt_iconResource="fa_cloud_download_alt"
app:bkt_iconArea="30dp"
app:bkt_iconTint="@color/colorAccent"
app:bkt_iconPadding="0dp"
app:bkt_iconMargin="10dp"
...
/>
...
</RootLayout>
You can also do it programmatically with ease and reusability of specific configurations
override fun onCreate(savedInstanceState: Bundle?) {
...
// Configuration instance
// You are opt to change specific & named configurations
// This configuration can be reused for adding multiple views programatically
val configuration = ButtonsKt(
text = "DECLARED VIA CODE",
textSize = 18f,
textStyle = BktTextStyle.BOLD,
...
)
// Create ButtonsKtView with the desired configuration instance
val buttonsKtView = ButtonsKtView(this, configuration)
// Add custom view
rl_main.addView(buttonsKtView)
...
}
Joshua de Guzman | code@jmdg.io
Distributed under the MIT license.
- Fork it (https://github.com/joshuadeguzman/ButtonsKt/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request