nativescript-community / ui-material-components

Monorepo that contains all of the NativeScript Material Design plugins.
https://nativescript-community.github.io/ui-material-components/
Apache License 2.0
215 stars 80 forks source link

[Feature Request] Posibility of mat-prefix and mat-suffix icons in textfield #32

Open inONEL opened 4 years ago

inONEL commented 4 years ago

It would be nice if we could add material icons to the textfield

kryoware commented 3 years ago

Just in case someone still needs this. Not sure if this is the right way to do it tho. Tested on Android 9 - NS 6.x

Code


import { android as androidApp } from 'tns-core-modules/application'

...

// loaded event
textFieldLoaded({ object }) {
    // Grab Native view
    const inputLayout = object.android
    // Grab icon from res (replace "com.example.app" with your package name. "ic_add" with your icon name)
    const icon = com.example.app.R.drawable.ic_add
    // Convert it into a drawable for android
    const iconDrawable = androidApp.context.getResources().getDrawable(icon)

    inputLayout.setPrefixText("+63 ")
    inputLayout.setStartIconDrawable(iconDrawable)
}

Result

Screenshot_20201109-114631

farfromrefug commented 3 years ago

@kryoware I think it is the right way. Want to make a PR to add that both on iOS and Android ?