Last active
September 1, 2023 20:04
-
-
Save ibrahim-mrq/5913e9bba99d5ff9cfd0f28aacb1c48d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.package_name; | |
| import android.annotation.SuppressLint; | |
| import android.content.Context; | |
| import android.os.Handler; | |
| import android.util.AttributeSet; | |
| import android.widget.TextView; | |
| @SuppressLint("AppCompatCustomView") | |
| public class TypeWriter extends TextView { | |
| private CharSequence mText; | |
| private int mIndex; | |
| private long mDelay = 150; | |
| public TypeWriter(Context context) { | |
| super(context); | |
| } | |
| public TypeWriter(Context context, AttributeSet attrs) { | |
| super(context, attrs); | |
| } | |
| private Handler mHandler = new Handler(); | |
| private Runnable characterAdder = new Runnable() { | |
| @Override | |
| public void run() { | |
| setText(mText.subSequence(0, mIndex++)); | |
| if (mIndex <= mText.length()) { | |
| mHandler.postDelayed(characterAdder, mDelay); | |
| } | |
| } | |
| }; | |
| public void animateText(CharSequence text) { | |
| mText = text; | |
| mIndex = 0; | |
| setText(""); | |
| mHandler.removeCallbacks(characterAdder); | |
| mHandler.postDelayed(characterAdder, mDelay); | |
| } | |
| public void setCharacterDelay(long millis) { | |
| mDelay = millis; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <com.package_name.TypeWriter | |
| android:id="@+id/splash_btn_start" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:drawableRight="@drawable/ic_left_arrow" | |
| android:fontFamily="@font/font_regular" | |
| android:gravity="center" | |
| android:paddingHorizontal="20dp" | |
| android:text="إبدا الأن" | |
| android:textColor="@color/colorWhite" | |
| android:textSize="20sp" | |
| android:textStyle="bold" | |
| tools:ignore="RtlHardcoded" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment