I have so many util codes for UI and want to create a android library for each of them. With all my research I have done below things.
File -> new module. Create an android library
in build.gradle file implement the library
implementation project(':app:FirstLibrary')Kotlin and xml file in library is below
FirstLib.kt
class FirstLib(mContext: Context) : Activity() {
private var mContext: Context? = null
private var view: View? = null
fun s(message: String?) {
layoutInflater.inflate(R.layout.first_lib_view, null)
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show()
}
}
first_lib_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Om Namah Shivaya"
android:textSize="16sp" />
</LinearLayout>
- Next, I'm trying to access this UI library in main xml file like below
<com.example.firstlibrary.FirstLib
android:layout_width="match_parent"
android:layout_height="match_parent"
tools="ajkdfbj"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Now I'm not getting anything. Even toast message was not coming.
How to create UI library in Android and use it. I have my own custom video players, audio players, image gradient views etc. I need to make all those libraries now. Thanks for reading