textview

How to apply the background color for the ImageSpan in Android?

為{幸葍}努か 提交于 2020-03-02 12:22:28
问题 I want to apply the background color for the Image span dynamically in Android. Could you please suggest any ideas? 回答1: You can't use BackgroundColorSpan and ImageSpan at the same time. The idea is creating an ImageSpan from LayerDrawable with background and image layers. Please look at the following code: Kotlin: val span: Spannable = SpannableString("This is ic launcher with background") val myImage: Drawable = resources.getDrawable(R.drawable.ic_launcher_foreground) val background =

android 重写TextView 实现文字整齐排版

此生再无相见时 提交于 2020-03-01 10:13:50
//XRTextView类 package rong.android.test; import org.json.JSONArray; import org.json.JSONException; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; public class XRTextView extends TextView{ private final String namespace = "rong.android.TextView"; private String text; private float textSize; private float paddingLeft; private float paddingRight; private float marginLeft; private float marginRight; private int textColor; private

android中用Spannable在TextView中设置超链接、颜色、字体

人盡茶涼 提交于 2020-02-28 23:51:42
昨晚研读 ApiDemo 源码至 com.example.android.apis.text.Link 类。首先,看一下其运行效果:   要给 TextView 加上效果,方式主要有几种:   第一种,自动应用效果,使用 android:autolink 属性,如:   Java代码 ? 代码片段,双击复制 01 02 03 04 05 06 07 08 09 10 11 android:id= "@+id/text1" android:layout_width= "match_parent" android:layout_height= "match_parent" android:autoLink= "all" android:text= "@string/link_text_auto" />   第二种,在文本中使用 标签,如:   Java代码 ? 代码片段,双击复制 01 02 03 04 05 06 07 text2: This is some other text, with a link specified via an tag. Use a \"tel:\" URL to dial a phone number   第三种,和第二种其实是一样的,只不过将文本改在 JAVA 代码中,如:   Java代码 ? 代码片段,双击复制 01 02 03 04 05 06

Databinding selector in TextView textColor

南楼画角 提交于 2020-02-27 07:56:48
问题 I am trying to set colors from a textview based on the number of unread messages in a channel. Like so: android:textColor="@{channel.unreadCount > 0 ? @color/selector_conversation_row_title_unread : @color/selector_conversation_row_title_read}" this only sets the color of the title, while: android:textColor="@color/selector_conversation_row_title_unread" this code sets the textColor as a selector, and if i press the TextView the color changes unlike the first statement. selector_conversation

Numbers inside TextView getting reversed when formatted in RTL

谁说胖子不能爱 提交于 2020-02-27 03:32:47
问题 Numbers inside TextView are getting reversed when formatted in RTL. When numbers are at the end of a text inside a TextView they getting reversed. How can I solve this programmatically? As an example, the numbers below are reversed: They should be displayed like: 回答1: The misunderstand: Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة". The problem and

How to set font weight as light, regular in Android

自闭症网瘾萝莉.ら 提交于 2020-02-26 11:08:08
问题 I have 3 text views. I need to set their weight as Light, Regular and Condensed. Can someone help me on how to achieve this in Android? 回答1: Use android:textStyle on a TextView to set the text style like bold , italic or normal. Here is an example of a TextView with a bold text style: <TextView android:id="@+id/hello_world" android:text="hello world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold"/> If you want to use light or condensed, you

Why does TextView have end padding when multi line?

ぐ巨炮叔叔 提交于 2020-02-26 09:12:33
问题 If you have a TextView with layout_width="wrap_content" and it has to wrap to a second line to contain the text, then it will size its width to use up all of the space available (respecting margins etc). But why is there padding at the end of the view? I just told it to wrap_content , so it should wrap that content! This seems like a bug, this is visible in the chat UI of the stock Messenger app. (The image is from my own app though. But that extra space is definitely not in the 9 patch.) Any

Why does TextView have end padding when multi line?

半城伤御伤魂 提交于 2020-02-26 09:12:09
问题 If you have a TextView with layout_width="wrap_content" and it has to wrap to a second line to contain the text, then it will size its width to use up all of the space available (respecting margins etc). But why is there padding at the end of the view? I just told it to wrap_content , so it should wrap that content! This seems like a bug, this is visible in the chat UI of the stock Messenger app. (The image is from my own app though. But that extra space is definitely not in the 9 patch.) Any

add Layout programmatically inside another one

纵饮孤独 提交于 2020-02-19 10:08:49
问题 I have an xml file (option_element.xml) that contains a ImageView and a TextView <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="-18dp" > <ImageView android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/option_button" />

Android textview html font size tag

百般思念 提交于 2020-02-17 05:38:11
问题 I use <font size ="50"> tag in android textview like this resultTextView.setText(Html.fromHtml("<font size='50' color='#337744'>Text Message</font>")); resultTextView.setText(Html.fromHtml("<font size=\"50\" color='#337744'>Text Message</font>")); but the problem is the color tag works but size tag doesn't work In this blog http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html it is given that font size tag works. What's wrong in my code? 回答1: There is exact