只要用戶在edittext中輸入「house」,就試着着色一個詞(房子)。這是我做了什麼:如果在edittext中包含該文字的話,如何爲android文本的一部分着色
if (textA.getText().toString().equals("house")){
String name = String.valueOf(textA.getText().toString().equals("house"));
name.setTextColor(Color.parseColor("#bdbdbd"));
}
我的XML是如下
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:orientation="vertical"
android:padding="5dp">
<EditText
android:id="@+id/textA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:inputType="textMultiLine"
android:maxLines ="4"
android:maxLength ="2000"
android:textColorHint="@color/grey"
android:background="@android:color/transparent"
android:gravity="top"/>
</LinearLayout>
然而,這會導致應用程序崩潰。不知道我做錯了什麼。我是Android新手。有什麼建議嗎?
什麼是logcat的說?什麼是崩潰錯誤? – John61590
你應該得到'name.setTextColor'的編譯時錯誤,因爲名稱是字符串(本地變量) – Manmohan