Skip to content

Instantly share code, notes, and snippets.

@ercnksgl
ercnksgl / CustomEditText.kt
Created September 15, 2022 19:06
Custom component CustomEditText
package com.ercnksgl.customcomponent.custom
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Space
import androidx.annotation.DrawableRes
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
@ercnksgl
ercnksgl / custom_edittext_layout
Created September 15, 2022 18:59
Custom component edittext layout
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:layout_height="wrap_content"
tools:layout_width="match_parent"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/titleTextView"
@ercnksgl
ercnksgl / themes.xml
Created September 15, 2022 18:54
Custom component themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
.
.
.
.
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:background">@drawable/bg_edittext</item>
<item name="android:textColor">@color/color_red_300</item>
@ercnksgl
ercnksgl / attrs.xml
Created September 15, 2022 18:48
Custom component attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomTextView">
<attr name="android:title" />
<attr name="startIcon" format="reference"/>
<attr name="customEditTextStartIconStyle" format="reference" />
<attr name="customEditTextStyle" format="reference" />
</declare-styleable>
</resources>
@ercnksgl
ercnksgl / activity_main.xml
Created September 15, 2022 18:43
Custom component MainActivity
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ercnksgl.customcomponent.MainActivity">
<com.ercnksgl.customcomponent.custom.CustomEditText
android:id="@+id/customEditText"
@ercnksgl
ercnksgl / TextCustomizer.kt
Last active September 15, 2022 07:34
Text customizer
import android.text.Spanned
import androidx.core.text.HtmlCompat
class TextCustomizer {
class Builder(private val allText: String) {
private val parts = arrayListOf<Pair<String, Customize>>()
fun addTextToReplace(part: String, customize: Customize)= apply {
@ercnksgl
ercnksgl / Customize.kt
Last active September 14, 2022 11:55
Customize Object
import android.content.Context
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
/**
* Set font types and color to customize text.
*/
data class Customize(
var hexColor: Int? = null,
val isItalic: Boolean = false,