esafirm / android-image-picker

Image Picker for Android 🤖
MIT License
1.11k stars 327 forks source link

Option to change camera icon color #434

Open or-else opened 1 year ago

or-else commented 1 year ago

Would like to reopen #144.

I would like to be able to change color of the Camera icon in the toolbar menu.

The change in the code is trivial, specifically, add one line to the menu item in https://github.com/esafirm/android-image-picker/blob/main/imagepicker/src/main/res/menu/ef_image_picker_menu_main.xml

<item
        android:id="@+id/menu_camera"
        android:icon="@drawable/ef_ic_camera_white"
        android:title="@string/ef_camera"
        app:showAsAction="always"
        app:iconTint="?cameraIconTint" <<<< add this line
        tools:ignore="AlwaysShowAction" />

Then define the color cameraIconTint in your style.xml. That's it.

Alternatively, you can use vector icons with android:tint color defined in style. Like this:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:tint="?android:textColorPrimary" <<<<< ------ this line
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="...." />
</vector>

It's a highly unusual design decision to require custom component just to change color of a UI element. That's usually done with style.xml.

In the #144 you suggest to use custom components, but unfortunately there are no examples on how to do it. Would it be possible to provide some guidance on how to use it beyond what you have in custom_components.md?

I don't see anything related to toolbar styling in interface ImagePickerComponents:

    val imageLoader: ImageLoader
    val imageFileLoader: ImageFileLoader
    val cameraModule: CameraModule
or-else commented 1 year ago

BTW, it would be nice to replace the PNG icon with an SVG icon.

or-else commented 1 year ago

Just checked: it's not possible to subclass ImagePickerActivity and override onOptionsMenuCreated because ImagePickerLauncher.resultLauncher is private.

The only way to change color of the icon is to fork the project and edit the code which is a shame.