How to set text color from jni on android?

Viewed 33

I'm working on an android app and i want to know if there's any way to set an color to my texts from C++ (JNI), just like i do in java:

private TextView text;
text = findViewById(R.id.textview);
text.setTextColor(int);

some code i've tried to use (i use simillar code for setText (not color) and it works):

void setTextColor(JNIEnv *env, jobject thiz, const char* id, int color) {
    jclass idClass = env->FindClass(packagename);
    jmethodID findViewById = env->GetMethodID(env->GetObjectClass(thiz), "findViewById", "(I)Landroid/view/View;");
    jobject string = env->CallObjectMethod(thiz, findViewById, env->GetStaticIntField(idClass, env->GetStaticFieldID(idClass, id, "I")));
    jmethodID setTextC = env->GetMethodID(env->GetObjectClass(string), "setTextColor", "(Ljava/lang/Integer;)V");
    env->CallVoidMethod(string, setTextC, color);
}

Edit: Issue solved in the comments.

0 Answers
Related