Giter Site home page Giter Site logo

custom views, view attrs, attrs about anko HOT 10 CLOSED

yoavst avatar yoavst commented on August 15, 2024
custom views, view attrs, attrs

from anko.

Comments (10)

nschwermann avatar nschwermann commented on August 15, 2024 2

Here is what I ended up doing for this...

fun Context.attribute(value : Int) : TypedValue {
    var ret = TypedValue()
    getTheme().resolveAttribute(value, ret, true)
    return ret
}

fun Context.attrAsDimen(value : Int) : Int{
    return TypedValue.complexToDimensionPixelSize(attribute(value).data, getResources().getDisplayMetrics())
}

//inside the DSL of an activity onCreate
    val toolbar = toolbarSupport{
        setTitle("hello")
        setElevationCompat(dip(4))
        backgroundColor = attribute(R.attr.colorPrimary).data
    }.layoutParams(width = org.jetbrains.anko.matchParent, height = attrAsDimen(net.schwiz.koat.R.attr.actionBarSize))

from anko.

yanex avatar yanex commented on August 15, 2024
  1. Maybe there will be an intension in Anko plugin that will create new properties for Java get/set methods.
  2. There is a property View.minimumHeight : Int.
  3. backgroundColor = getResources().getColor(android.R.color.primary_text_dark).

from anko.

yoavst avatar yoavst commented on August 15, 2024

can we have something like easy way to pass hardcoded attrs?

from anko.

yanex avatar yanex commented on August 15, 2024

What hardcoded attrs do you mean?

from anko.

yoavst avatar yoavst commented on August 15, 2024

custom attrs :)

from anko.

yoavst avatar yoavst commented on August 15, 2024

Hi, how do I get android:layout_height="?attr/actionBarSize" functionality? or any other attr?

from anko.

smallmouse2009 avatar smallmouse2009 commented on August 15, 2024

custom views :setBackgroundResource、setBackgroundColor() both don't work even though i override the onDraw method.

from anko.

smallmouse2009 avatar smallmouse2009 commented on August 15, 2024

this is how i use attr.
val a = context.obtainStyledAttributes(attrs, R.styleable.CustomTitleView)

        //获取属性
        if (a.hasValue(R.styleable.CustomTitleView_center_title)) {
            centerTitle = a.getString(R.styleable.CustomTitleView_center_title)
        }
        if (a.hasValue(R.styleable.CustomTitleView_right_title)){
            rightTitle = a.getString(R.styleable.CustomTitleView_right_title)
        }
        if(a.hasValue(R.styleable.CustomTitleView_bgcolor)){
            bgcolor = a.getResourceId(R.styleable.CustomTitleView_bgcolor, R.color.colorAccent)
        }
        if(a.hasValue(R.styleable.CustomTitleView_leftsrc)){
            leftsrc = a.getResourceId(R.styleable.CustomTitleView_leftsrc, R.drawable.abc_btn_radio_material)
        }

from anko.

smallmouse2009 avatar smallmouse2009 commented on August 15, 2024

or use like this.
//获取属性
for (i: Int in 0..a.indexCount) {
var attr : Int = a.getIndex(i)
when(attr){
R.styleable.CustomTitleView_leftsrc ->
leftsrc = a.getResourceId(attr, R.drawable.abc_btn_radio_material)
R.styleable.CustomTitleView_right_title -> rightTitle = a.getString(attr)
R.styleable.CustomTitleView_center_title -> centerTitle = a.getString(attr)
}
}

from anko.

ezamelczyk avatar ezamelczyk commented on August 15, 2024

There's now a method for this dimenAttr(R.attr.actionBarSize)

from anko.

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.