Comments (10)
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.
- Maybe there will be an intension in Anko plugin that will create new properties for Java get/set methods.
- There is a property
View.minimumHeight : Int
. backgroundColor = getResources().getColor(android.R.color.primary_text_dark)
.
from anko.
can we have something like easy way to pass hardcoded attrs?
from anko.
What hardcoded attrs do you mean?
from anko.
custom attrs :)
from anko.
Hi, how do I get android:layout_height="?attr/actionBarSize" functionality? or any other attr?
from anko.
custom views :setBackgroundResource、setBackgroundColor() both don't work even though i override the onDraw method.
from anko.
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.
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.
There's now a method for this dimenAttr(R.attr.actionBarSize)
from anko.
Related Issues (20)
- Alerts with no system bar, or: how to get dialog before show() ? HOT 1
- How to use linearLayout in verticalLayout? HOT 1
- hintTextColor can not work in anko? HOT 1
- Error: void org.jetbrains.anko.appcompat.v7._AlertDialogLayout.forceUniformWidth(int, int) is not being kept as e, but remapped to d
- Feature request: share file
- Android Q support
- Maybe Not update anymore for this project? HOT 1
- Maybe Not update anymore for this project? HOT 11
- Is this project discontinued? HOT 5
- Textview cannot accept new line from Resources strings HOT 2
- something issues of anko.include() dsl
- ***** BEWARE -- this project seems to be abandoned. ***** HOT 14
- Fix reference - Listeners not working HOT 1
- about Anko performance HOT 8
- Selector no cancel listener HOT 1
- textView.setMaxWidth() does not work
- Is SDK28 Available In A Repo Somewhere? HOT 1
- Style selector text? HOT 1
- Please archive this repository. HOT 3
- What if I don't want to add the view directly?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anko.