Skip to content

Flag Emoji Support

Harsh B. Bhakta edited this page Mar 18, 2019 · 5 revisions

Flag Emoji Support (BETA)

  • Issue #285 came up with a really exciting idea to use flag emoji instead of flag images. This can reduce the library size and flag style can blend with OS theme.

Screen after enabling emoji flags,

How to enable

  • Make sure you are using v2.2.5 or higher.
  • Now simply add app:ccp_useFlagEmoji="true" to XML Layout and CCP will start using Flag Emoji.
                     <com.hbb20.CountryCodePicker
                      android:id="@+id/ccp"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      app:ccp_useFlagEmoji="true" />

Getting incorrect preview in Android Studio Layout

  • Sometimes Android Studio is Unable to show flag emoji in preview for some countries due to Android Studio Fonts.
  • In such conditions, it will place boxed 2 digit name code. For example, instead of new Zealand flag NZ is rendered.
  • This can lead to incorrect measurement in preview.
  • Add additional app:ccp_useDummyEmojiForPreview="true" to your CCP XML. This will put Checkered Flag Emoji instead of country flag. And your preview will be something like this:
  • This will override flag emoji only during preview in Android Studio. When you run, your Android Device's font will be used. If your Android device has that emoji then it will be shown correctly.

Problems with FLAG EMOJI approach

While we were excited about the approach, we realized following problems. Right now, this feature is still in BETA.

  1. If your users are running on older device which does not have emoji support for newly released flag emojis then they will not be rendered correctly.
  2. Emojis are platform specific. So they might not look just the same on devices from different manufacturer. If you are concerned about consistency, you might want to stick with flag images only.
  3. Library artifact still contain flag images. So library size will not be reduced even if you are using emoji flags.
Clone this wiki locally