2dxgujun / kpan Goto Github PK
View Code? Open in Web Editor NEW:four_leaf_clover:Kotlin wrapper around SpannableStringBuilder to bring modern API
License: Apache License 2.0
:four_leaf_clover:Kotlin wrapper around SpannableStringBuilder to bring modern API
License: Apache License 2.0
vOfficialCommunity.vText.text = span {
communities.forEachIndexed { i, community ->
image(getDrawable(community)!!) {
}
// TODO Kpan horizontal spacing
if (i < communities.size - 1) {
+" "
}
}
}
Thank you for the helpful library? how do i add custom functions such as a paint function to draw an underline...
that is i want a dotted underline under a span? could you please guide some.
初次看到,真的是被惊艳到了,原来kotlin还可以这样写,十分佩服,所以尝试去看 了下源码,对下面这块代码看的不是特别明白,我也是kotlin初学者,想了很久没有明白,所以来这里请教下您
fun span(init: Span.() -> Unit): Span = Span().apply {
setGlobalStyles()
init()
build()
}
主要是init: Span.() -> Unit
这块代码看不懂,我仿照写了写,会报错,但是又不知道为什么您的代码没有问题,所以想您给点提示,非常感谢
Hello,
I downloaded sample app and Clickable span don't work for me.
java.lang.NoSuchMethodError
me.gujun.android.span.Span.length(Proguard:29)
android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:268)
me.gujun.android.span.Span.me.gujun.android.span.Span build()(Proguard:157)
me.gujun.android.span.SpanKt.me.gujun.android.span.Span span$default(me.gujun.android.span.Span,java.lang.CharSequence,kotlin.jvm.functions.Function1,int,java.lang.Object)(Proguard:257)
##_parent_##2##_parent_##
##_child_## me.gujun.android.span.Span span(kotlin.jvm.functions.Function1)##_child_##
##_child_## me.gujun.android.span.Span span(me.gujun.android.span.Span,java.lang.CharSequence,kotlin.jvm.functions.Function1)##_child_##
me.gujun.android.span.SpanKt.me.gujun.android.span.Span span$default(me.gujun.android.span.Span,java.lang.CharSequence,kotlin.jvm.functions.Function1,int,java.lang.Object)(Proguard:253)
##_parent_##2##_parent_##
##_child_## me.gujun.android.span.Span span(kotlin.jvm.functions.Function1)##_child_##
##_child_## me.gujun.android.span.Span span(me.gujun.android.span.Span,java.lang.CharSequence,kotlin.jvm.functions.Function1)##_child_##
我自定义了一个类,是它的问题吗
/**
* 取消url的下划线
* mrtan on 2018/3/21.
*/
class NewsSpan : URLSpan {
constructor(url: String): super(url)
constructor(src: Parcel): super(src)
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
}
}
能否把取值设置为枚举或者@stringdef,用的时候去翻文档很麻烦,谢谢
private class LinkMovementMethodTouchListener : View.OnTouchListener {
override fun onTouch(
v: View,
event: MotionEvent
): Boolean {
val widget = v as TextView
val action = event.action
if (widget.text is SpannedString && action == MotionEvent.ACTION_UP) {
var x = event.x.toInt()
var y = event.y.toInt()
x -= widget.totalPaddingLeft
y -= widget.totalPaddingTop
x += widget.scrollX
y += widget.scrollY
val layout = widget.layout
val line = layout.getLineForVertical(y)
val off = layout.getOffsetForHorizontal(line, x.toFloat())
val links = (widget.text as SpannedString).getSpans(off, off, ClickableSpan::class.java)
if (links.isNotEmpty()) {
links[0].onClick(widget)
return true
}
}
return true
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.