Android-Iconics

repository·develop·Indexed 26 days ago

https://github.com/mikepenz/android-iconics

A library that allows developers to include any icon font as vector icons in Android projects. It supports XML Drawables, Custom Views (IconicsButton, IconicsImageView, IconicsTextView), and Jetpack Compose. The library provides high scalability, color customization, and support for various icon fonts including Google Material, FontAwesome, and Octicons.

Tokens
3.7K
Snippets
8
Records
20
Agent score
90%

What's inside Android-Iconics

  1. Migrate from core v3.x.x to 4.x.x

    develop

    When upgrading from version 3.x.x to 4.x.x, note the following breaking changes:

    • Kotlin-First: The library is now Kotlin-first.
    • Font Storage: Fonts are now stored using the default Android way (moved from common assets to font-specific resource assets).
    • Iconics Initialization: Context is no longer required for Iconics as the application context is retrieved via ContentProvider.
    • Iconics.Builder: Iconics.IconicsBuilder has been renamed to Iconics.Builder, and the ctx(Context) method has been removed.
    • IconicsDrawable API:
      • Methods like *Res(int), *Px(int), and *Dp(int) have been replaced by IconicsSize and IconicsColor classes.
      • Constants TOOLBAR_ICON_SIZE and TOOLBAR_ICON_PADDING are now located in IconicsSize.
      • All getters now use property syntax.
      • Producer-provided methods from Android-Iconics Kt are included in the class and may return nullable values (values are only set if not null).
    • Utility Classes: All utils classes and typeface libraries can no longer be instantiated. enableShadowSupport(View) has moved to IconicsUtils.
    • ITypeface: The getTypeface(Context) method is replaced by the rawTypeface field. It automatically retrieves the raw font from a file via the provided fontRes.
    • Community Material Icons: If using icons via code, the enum has been split due to size limits:
      • CommunityMaterial.Icon: Icons starting with a through g.
      • CommunityMaterial.Icon2: Icons starting with h through z.
  2. Install Android-Iconics core and views

    develop

    To use Android-Iconics, you must first provide the core library dependency. Optionally, you can add the views dependency to access UI widgets like IconicsButton and IconicsImageView.

    dependencies {
        //the core iconics library (without any widgets)
        implementation "com.mikepenz:iconics-core:${latestAndroidIconicsRelease}"
        implementation "androidx.appcompat:appcompat:${versions.appCompat}"
    }
    
    //this adds all ui view widgets (IconicsButton, IconicsImageView, ...)
    implementation "com.mikepenz:iconics-views:${latestAndroidIconicsRelease}"
  3. Use Iconics via XML (Drawable and Custom Views)

    develop

    To use icons in XML, use the syntax {fontId}-{iconName} (e.g., gmd-favorite).

    Drawable XML (API 24+)

    Specify the icon in your drawable folder using IconicsDrawable:

    <com.mikepenz.iconics.IconicsDrawable
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:ico_icon="gmd_favorite"
        app:ico_color="#0000FF"
        app:ico_contour_width="1dp"
        app:ico_contour_color="#00FFFF"
        app:ico_size="24dp" />

    Custom Views

    IconicsImageView

    <com.mikepenz.iconics.view.IconicsImageView
        android:layout_width="72dp"
        android:layout_height="72dp"
        app:iiv_color="@android:color/holo_red_dark"
        app:iiv_icon="gmd-favorite" />

    IconicsTextView

    Use the {fontId-iconName} syntax within the text string:

    <com.mikepenz.iconics.view.IconicsTextView
        android:text="abc{hif-test}defgh{faw-adjust}ijk"
        android:layout_width="wrap_content"
        android:layout_height="56dp" />

    IconicsButton

    <com.mikepenz.iconics.view.IconicsButton
        android:text="{faw-adjust} Button"
        android:layout_width="120dp"
        android:layout_height="60dp"/>
  4. Migrate from core v4.x.x to 5.x.x

    develop

    When upgrading from version 4.x.x to 5.x.x, note the following breaking changes:

    • IconicsDrawable API Changes: All with* methods have been replaced with properties. Raw setters (e.g., for int color, string, or pixel values) are now direct. Other properties have been moved to extension functions.
    • Context Dependency: IconicsDrawable now depends on Resources and Theme instead of Context. All corresponding methods have been refactored to accept Resources and Theme.
    • XML Usage: You can now use IconicsDrawable via XML for API 24+.
    • Atomic Updates: The .apply method is specialized; it ensures the drawable is not invalidated until all changes within the block are completed.
  5. Migrate from 2.9.0 to 2.9.x (Module Split)

    develop

    In version 2.9.0, the library was split into iconics-core and iconics-views to reduce the core size.

    • The core dependency remains: compile "com.mikepenz:iconics-core:2.9.0@aar".
    • For all UI widgets, you must now also add: compile "com.mikepenz:iconics-views:2.9.0@aar"
  6. Use Android-Iconics with Jetpack Compose

    develop

    To use experimental Compose support, add the iconics-compose dependency. Use the provided Image wrapper and set the icon.

    implementation "com.mikepenz:iconics-compose:${latestAndroidIconicsRelease}"
    Image(
        GoogleMaterial.Icon.gmd_access_alarm,
        colorFilter = ColorFilter.tint(MaterialTheme.colors.primary),
    )
  7. Add icon font dependencies

    develop

    Android-Iconics requires specific font dependencies to display icons. Note that fonts ending with -kotlin require at least v4.x of Android-Iconics, and v5.1.x or newer requires the latest font versions.

    If using a Gradle version catalog, you must specify the aar type manually: implementation(libs.material.typeface) { artifact { type = "aar" } }

    implementation 'com.mikepenz:google-material-typeface:4.0.0.3-kotlin@aar'
    implementation 'com.mikepenz:google-material-typeface-{outlined|rounded|sharp}:4.0.0.2-kotlin@aar'
    implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.9-kotlin@aar'
    implementation 'com.mikepenz:fontawesome-typeface:5.9.0.3-kotlin@aar'
    implementation 'com.mikepenz:octicons-typeface:11.1.0.1-kotlin@aar'
    implementation 'com.mikepenz:meteocons-typeface:1.1.0.8-kotlin@aar'
    implementation 'com.mikepenz:community-material-typeface:7.0.96.1-kotlin@aar'
    implementation 'com.mikepenz:weather-icons-typeface:2.0.10.8-kotlin@aar'
    implementation 'com.mikepenz:typeicons-typeface:2.0.7.8-kotlin@aar'
    implementation 'com.mikepenz:entypo-typeface:1.0.0.8-kotlin@aar'
    implementation 'com.mikepenz:devicon-typeface:2.0.0.8-kotlin@aar'
    implementation 'com.mikepenz:foundation-icons-typeface:3.0.0.8-kotlin@aar'
    implementation 'com.mikepenz:ionicons-typeface:2.0.1.8-kotlin@aar'
    implementation 'com.mikepenz:pixeden-7-stroke-typeface:1.2.0.6-kotlin@aar'
    implementation 'com.mikepenz:material-design-icons-dx-typeface:5.0.1.3-kotlin@aar'
    implementation 'com.mikepenz:phosphor-typeface:1.0.0.1-kotlin@aar'
    implementation 'com.mikepenz:simple-icons-typeface:17.0.0.3@aar'
  8. Enable Iconics features on Android base views (v2.5.0)

    develop

    Starting from version 2.5.0, the preferred way to enable Iconics features on base views (like ImageView or TextView) is to define IconicsLayoutInflater as the default LayoutInflater. This approach provides compatibility with Calligraphy.

    This requires an Activity that extends AppCompatActivity or implements AppCompatDelegate.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
        //...
        super.onCreate(savedInstanceState);
    }

    If you do not extend AppCompatActivity or implement AppCompatDelegate, you can still wrap the baseContext:

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
    }
  9. Fix IconicsView styling issues with AppCompat 1.4.x

    develop

    AppCompat v1.4.x enables emoji support by default in all AppCompat* views, which interferes with IconicsView* (from the iconics-views module) when applying spannable styles. To resolve this, disable emoji support on the view in your XML layout:

    app:emojiCompatEnabled="false"