liubaoyua / CustomText-MD

CustomText with MD
74 stars 20 forks source link

replace text #2

Open nylonW opened 8 years ago

nylonW commented 8 years ago

Hi, what is the easiest way to globally replace text which I can use in my app? I know package of app that i want to mod.

liubaoyua commented 8 years ago

are you want to intergrate the replace text function in you app? if you have xposed, you can hook the setText method in TextView.class and modify the text before setTextMethod。

nylonW commented 8 years ago

Can you give me any example? e.g. if i want to change string "text" to "new text" . Xposed of course. Thank you.

liubaoyua commented 8 years ago

a sample code. hope it works for you

XposedHelpers.findAndHookMethod(TextView.class, "setText", CharSequence.class, TextView.BufferType.class, boolean.class, int.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); CharSequence cs = (CharSequence) param.args[0]; if (cs != null && cs instanceof String) { String origin = (String) cs; String result = origin.replace("text", "new text"); param.args[0] = result; } } });

nylonW commented 8 years ago

Thank you it works, but how to use it only in specific package? And one more question, how to use it only if my string to replace equals "text". E.g. it works if my string equals "somethingtextsomething" and i don't want it.

liubaoyua commented 8 years ago

@nylonW

use the lpparm.packageName.equals("you packageName ") to check you app ...also the text can be check like that before "replace".