spannable

ImageSpan on EditText (smileys). With SwiftKey Keyboard doesnt work

扶醉桌前 提交于 2019-12-02 19:47:31
I am doing a simple chat application and i want to show smileys on edittext while writing the message. I have this to identify wich characters will be subsituted by an Image throught an ImageSpan (this is called only when an smileys character is inserted on EditText): for (index = start; index < start+num_chars; index++) { if (index + 1 > editable.length()) continue; if(emoticons.containsKey(editable.subSequence(index, index + 1).toString())){ int length=1; Drawable drawable = context.getResources().getDrawable(emoticons.get(editable.subSequence(index, index + 1).toString())); Bitmap bitmap =

Combining Spannable with String.format()

社会主义新天地 提交于 2019-12-02 18:08:47
Suppose you have the following string: String s = "The cold hand reaches for the %1$s %2$s Ellesse's"; String old = "old"; String tan = "tan"; String formatted = String.format(s,old,tan); //"The cold hand reaches for the old tan Ellesse's" Suppose you want to end up with this string, but also have a particular Span set for any word replaced by String.format . For instance, we also want to do the following: Spannable spannable = new SpannableString(formatted); spannable.setSpan(new StrikethroughSpan(), oldStart, oldStart+old.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new

Remove style on spans

僤鯓⒐⒋嵵緔 提交于 2019-12-02 15:21:58
问题 I have used this StyleSpanRemover to remove style from selected text, but i have a problem. I want to have a bold button that toggle bold style of selected text. it means if the selected text (or part of that) is not bold, bold all of them; and if all of selected text is bold, remove bold style from it. But when i use this code, after one removing bold style on a text and again bolding it, getStyle() always returns Typeface.NORMAL Here is the code i have used: boolean isAllSpansBold = true; /

Remove style on spans

天大地大妈咪最大 提交于 2019-12-02 03:58:52
I have used this StyleSpanRemover to remove style from selected text, but i have a problem. I want to have a bold button that toggle bold style of selected text. it means if the selected text (or part of that) is not bold, bold all of them; and if all of selected text is bold, remove bold style from it. But when i use this code, after one removing bold style on a text and again bolding it, getStyle() always returns Typeface.NORMAL Here is the code i have used: boolean isAllSpansBold = true; /** * Bold selected text */ Spannable spannable = new SpannableString(mEditTextContent.getText());

Spannable String Error

筅森魡賤 提交于 2019-12-02 01:55:48
I am trying to display some text in an alert dialog box as a hyperlink. Part of the process requires me to use SpannableString to format some text. The problem is that my application experiences a runtime error on the SpannableString part of my code. TextView Tv= (TextView) findViewById(R.id.textView3); SpannableString s = new SpannableString("www.google.com"); Linkify.addLinks(s, Linkify.WEB_URLS); Tv.setText(s); Tv.setMovementMethod(LinkMovementMethod.getInstance()); I looked in the DDMS and the Error says Java.Lang.NullPointerException. Has anyone experienced this? I Should be able to pass

How to create a empty bullet paragraph by BulletSpan?

放肆的年华 提交于 2019-12-01 21:45:18
I wanted to create a empty bullet paragraph, but it didn't work. This is my code: EditText contentET = (EditText) findViewById(R.id.content); contentET.setText("abc\n123\n"); Spannable s = contentET.getText(); s.setSpan(new BulletSpan(), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE); s.setSpan(new BulletSpan(), 4, 5, Spannable.SPAN_INCLUSIVE_INCLUSIVE); s.setSpan(new BulletSpan(), 7, 8, Spannable.SPAN_INCLUSIVE_INCLUSIVE); contentET.setText(s); When i ran above code, it seemed this line doesn't work s.setSpan(new BulletSpan(), 7, 8, Spannable.SPAN_INCLUSIVE_INCLUSIVE); Instead, i saw an unexpected

Searching in Listview with searched textcolor highlighted in Listview Android

大憨熊 提交于 2019-12-01 12:03:27
问题 I Have a listview with arrayadapter .. i need to implement this in my music application ... help me out public class Search_Class extends Activity { EditText searchedit; ListView listview3; SongsManager songManager; Context context; String[] abc; ArrayList<String> names; ArrayList<String> arrayList; ArrayAdapter<String> ad; private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); @Override protected void onCreate(Bundle savedInstanceState) { // TODO

How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder?

拟墨画扇 提交于 2019-12-01 00:26:29
Here is what it looks like in the beginning when I haven't added any imagespan chips - As you can tell there the cursor is placed at the right size and the gravity is respected. Then when I add an imagespan, the cursor all of a sudden becomes bigger like this - I don't understand why this happens and I also don't know how to fix it, i.e. keep the cursor the same size. Finally when I start typing again, the cursor is all wierd while maintaining the size of the of the font and the span also moves a little to the bottom. I really want to the keep the cursor the same size and keep it centered I'm

How do I achieve a Facebook Messenger/ Google Hangouts like layout to preview selected items in search bar on ANDROID?

半腔热情 提交于 2019-11-30 22:25:24
Basically what I want to create can be best illustrated from a screenshot. I have a listview of people just like FB Messenger app. I want the ability for my users to have a search bar like the one shown in the screenshots. It should have the following properties: 1) Search bar should preview names of people selected in the list view 2) People can be de-selected by hitting backspace on any name in the preview search bar 3) The search bar should be able to filter the bottom list of people as the user types. I have a solution for propert 3) but I am clueless about the other two. Please HELP!!!

Android TextView superscript

主宰稳场 提交于 2019-11-30 20:32:31
问题 So I'm trying to add superscipt/subscript to a TextView, basically trying to make a fraction be displayed as 1 / 2 . Not sure where I'm going wrong, and I'm new with Android, so any help is appreciated. Thanks! SpannableStringBuilder numSpan = new SpannableStringBuilder(String.valueOf(num)); SpannableStringBuilder denSpan = new SpannableStringBuilder(String.valueOf(den)); numSpan.setSpan(new SuperscriptSpan(), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); denSpan.setSpan(new