GithubHelp home page GithubHelp logo

Comments (3)

pandulapeter avatar pandulapeter commented on June 21, 2024 1

Hi!
Thanks for bringing this up.
Indeed the current version of the library expects a Material theme.
But you're right, there's no reason for using MaterialButton (if your Activity has a Material theme, the layout inflater will replace all Views with their Material counterparts - something I didn't know back then).
I'll make sure to fix this in the next update, hopefully in the coming days. I'll keep you posted!

from beagle.

kingori avatar kingori commented on June 21, 2024 1

@pandulapeter thanks for the reply.
If you expect material-theme in this library, what about to wrap context with material-themed context?

This is code snippet I am using in my project

fun Activity.toMaterialContext(): Context {
    // this code is dangerous - using private material theme attribute
    val typedArray = this.theme.obtainStyledAttributes(intArrayOf(com.google.android.material.R.attr.isMaterialTheme))
    val isMaterialTheme = typedArray.getBoolean(0, false)
    typedArray.recycle()

    return if (isMaterialTheme) {
        this
    } else {
        wrapMaterialTheme( R.style.my_default_material_theeme )
        )
    }
}

fun Activity.wrapMaterialTheme(@StyleRes newMaterialThemeResId: Int): Context {
    return ContextThemeWrapper(
        this,
        newMaterialThemeResId
    ).apply {
        val materialContext = this
        val delegate = AppCompatDelegate.create(
            materialContext,
            requireNotNull(this),
            null
        )

        val inflater = LayoutInflater.from(materialContext)
        LayoutInflaterCompat.setFactory2(
            inflater,
            delegate as LayoutInflater.Factory2
        )
    }
}

If you apply this code, you can ensure library is using material themed context. But if user is applyed non-material theme, their theme is overridden. But I don't think this cause big(?) problem.

from beagle.

pandulapeter avatar pandulapeter commented on June 21, 2024

Thanks, that's really useful!
I'll try to take care of this as soon as possible :)

from beagle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.