Created
July 7, 2018 14:29
-
-
Save fnovoac/791fae1b537e094177ccd97d16bc7fe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.drawable.Drawable; | |
import android.support.v4.content.ContextCompat; | |
import android.text.Spannable; | |
import android.text.SpannableString; | |
import android.text.style.ForegroundColorSpan; | |
import com.fernandonovoa.fncspeedcontrol.myApp; | |
/** | |
* Created by liukun on 2017/10/9. | |
* 获取资源的工具类 | |
* https://github.com/tough1985/RetrofitMvvmDemo/blob/master/app/src/main/java/me/xiba/startlearnmvvm/util/ResUtil.java | |
*/ | |
public class ResUtil { | |
public static String getString(int resId) { | |
return myApp.getInstance().getString(resId); | |
} | |
public static int getColor(int resId) { | |
return ContextCompat.getColor(myApp.getInstance(), resId); | |
} | |
public static Drawable getDrawable(int resId) { | |
return ContextCompat.getDrawable(myApp.getInstance(), resId); | |
} | |
public static int getDimens(int resId) { | |
return myApp.getInstance().getResources().getDimensionPixelSize(resId); | |
} | |
/** | |
* 获取字体大小相同不同颜色的2个字符组成的字符串 | |
*/ | |
public static Spannable getColorString(String font, String after, int fontColor, int afterColor){ | |
String connectStr = new StringBuilder().append(font).append(after).toString(); | |
Spannable span = new SpannableString(connectStr); | |
int indexOfFont = connectStr.indexOf(font); | |
int indexOfAfter = connectStr.indexOf(after); | |
span.setSpan(new ForegroundColorSpan(fontColor), indexOfFont, indexOfFont + font.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
span.setSpan(new ForegroundColorSpan(afterColor), indexOfAfter, indexOfAfter + after.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
return span; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment