Android Kotlin SpannableString Example

Result activity_main.xml <?xml version=”1.0″ encoding=”utf-8″?> <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@android:color/white” tools:context=”.MainActivity”> <TextView android:id=”@+id/textView” android:textSize=”20sp” android:textAlignment=”center” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Hello World!” android:background=”@android:color/white” android:textColorHighlight=”@android:color/white” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toTopOf=”parent”/> </android.support.constraint.ConstraintLayout> MainActivity.kt class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val styledString = SpannableString( “By continue, you agree to Read more…

Shot but useful

Close/hide the Android Soft Keyboard everywhere you want, Change Image of ImageView programmatically in Android, Height of status bar in Android Close/hide the Android Soft Keyboard everywhere you want getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Change Image of ImageView programmatically in Android imageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.your_image)); Height of status bar in Android public static int getStatusBarHeight(Context context) { int Read more…

Email validation method – Android Kotlin

Here we will use regular expression (regex) to validate email address using Kotlin programming language. class EmailValidator { companion object { fun isEmailValid(email: String): Boolean { return Patterns.EMAIL_ADDRESS.toRegex().matches(email); } } } or fun String.isValidEmail(): Boolean = this.isNotEmpty() && Patterns.EMAIL_ADDRESS.matcher(this).matches() Please feel free to comment if you have newer techniques as Read more…

How to create content sliding using ViewPager in Kotlin

Make a content slider, modification from ViewPager with Kotlin programming language. Step 1. Add view pager into your layout activity_main.xml <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout 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”> <android.support.v4.view.ViewPager android:id=”@+id/viewPager” android:layout_width=”match_parent” android:layout_height=”match_parent” /> </RelativeLayout> Step 2. Create your fragment and its layout: fragment_viewpager_item.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/rootView” android:layout_width=”match_parent” android:layout_height=”match_parent” Read more…