Created
February 23, 2019 07:50
-
-
Save clxy/f6b756acbade08507092b21d41f74013 to your computer and use it in GitHub Desktop.
Emoji colors look faded. Emoji颜色发灰的解决办法
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
import android.content.Context; | |
import android.text.InputFilter; | |
import android.util.AttributeSet; | |
import androidx.annotation.Nullable; | |
import androidx.appcompat.widget.AppCompatTextView; | |
import androidx.emoji.widget.EmojiTextViewHelper; | |
/** | |
* 变更构建器里 init 方法的调用顺序 | |
* 不这么搞下,颜色发灰!看官方的截图就能明白。 | |
* @see https://github.com/googlesamples/android-EmojiCompat/blob/master/screenshots/1-main.png | |
* @see androidx.emoji.widget.EmojiTextView | |
* Created by clxy on 2017/12/01. | |
*/ | |
public class EmojiTextView extends AppCompatTextView { | |
private EmojiTextViewHelper mEmojiTextViewHelper; | |
/** | |
* Prevent calling {@link #init()} multiple times in case super() constructors | |
* call other constructors. | |
*/ | |
private boolean mInitialized; | |
public EmojiTextView(Context context) { | |
// super(context); | |
// init(); | |
this(context, null); | |
} | |
public EmojiTextView(Context context, @Nullable AttributeSet attrs) { | |
// super(context, attrs); | |
// init(); | |
this(context, attrs, 0); | |
} | |
public EmojiTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
init(); | |
} | |
private void init() { | |
if (!mInitialized) { | |
mInitialized = true; | |
getEmojiTextViewHelper().updateTransformationMethod(); | |
} | |
} | |
@Override | |
public void setFilters(InputFilter[] filters) { | |
super.setFilters(getEmojiTextViewHelper().getFilters(filters)); | |
} | |
@Override | |
public void setAllCaps(boolean allCaps) { | |
super.setAllCaps(allCaps); | |
getEmojiTextViewHelper().setAllCaps(allCaps); | |
} | |
private EmojiTextViewHelper getEmojiTextViewHelper() { | |
if (mEmojiTextViewHelper == null) { | |
mEmojiTextViewHelper = new EmojiTextViewHelper(this); | |
} | |
return mEmojiTextViewHelper; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment