Android programming method to implement partial color changes in TextView
This article describes the method of Android programming to implement partial color changes in TextView. Share it for your reference, as follows:
public class StringHandleExampleActivity extends Activity { /** Called when the activity is first created. */ private TextView textView; private String tempStr = "abcd12my medieval zx9yu5!f3,,"; private StringBuffer sb; private List<Integer> list; @Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(); sb = new StringBuffer(); list = new ArrayList<Integer>(); textView = (TextView) findViewById(); for (int i = 0; i < (); i++) { if (matcherReg(((i)))) { (i); } } SpannableStringBuilder style=new SpannableStringBuilder(tempStr); for (int i = 0; i < (); i++) { ((i)+", "); // (new BackgroundColorSpan(),(i),(i)+1,Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //Set the background color of the specified location textview (new ForegroundColorSpan(),(i),(i)+1,Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //Set the color of the text at the specified location } (style); } private boolean matcherReg(CharSequence c){ String regEx="[^0-9]"; Pattern p = (regEx); Matcher m = (()); if (()) { return false; } return true; } }
I hope this article will be helpful to everyone's Android programming design.
Related Articles
Use findViewByMe in Android to improve component search efficiency
This article mainly introduces the relevant knowledge of using findViewByMe in Android to improve component search efficiency. It has good reference value. Let's take a look with the editor below2017-03-03A summary of common attribute functions of Android EditText
This article mainly introduces the common attribute functions of Android EditText, and summarizes and analyzes the functions and specific usages of the common attributes of the EditText control in Android development. Friends who need it can refer to it.2016-06-06Add TextView strikethrough on Android (simple code)
I recently took on a project, and there are project requirements like this. There are such demands, that is, there are two prices under a product, one is the market price and the other is the sales price. At this time, a delete line must be added to the market price; how to achieve it? Below, the editor will share with you a simple code to implement Android to add TextView delete line2016-02-02Detailed explanation of Android image performance optimization
This article shares relevant knowledge points about Android performance optimization and picture optimization. Interested friends will refer to it.2018-07-07Android practical tutorial 43: Top loading and drop-down refresh
This article mainly introduces the 43rd Android practical tutorial, the upper loading and pull-down refresh, which has certain reference value. Interested friends can refer to it.2016-11-11Android string to Ascii code instance code
This article mainly introduces the method of converting Android strings to Ascii code. Please refer to it.2013-11-11Simple way to determine the orientation of the camera picture
Below, the editor will bring you an easy way to determine the orientation of the camera image on Android. The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor2017-03-03Android Coil vs. Glide in-depth analysis and exploration
This article mainly introduces Android Coil vs. Glide. Coil is a brand new image loading framework on Android. Its full name is coroutine image loader, that is, coroutine image loading library2023-02-02ObjectAnimator attribute animation source code analysis
Today, the editor will share with you an analysis of the source code of ObjectAnimator attribute animation. The editor thinks the content is quite good. Now I share it with you. It has good reference value. Friends in need will follow the editor to take a look.2019-01-01Android WebView FAQs and solutions
This article mainly introduces the common problems and solutions of Android WebView. Friends who need it can refer to it.2015-08-08