登錄按鈕的顏色切換樣式綁定失???
warnning信息:
Hardcoded string "登 錄", should use @string resource
代碼應該沒有問題:
activity_login.xml
styles_xml
<!--????登錄按鈕--> ????<style?name="commitBtn"> ????????<item?name="android:layout_width">match_parent</item> ????????<item?name="android:layout_height">@dimen/btnHeight</item> ????????<item?name="android:textColor">@android:color/white</item> ????????<item?name="android:textSize">@dimen/titleSize</item> ????????<item?name="android:layout_marginLeft">@dimen/marginSize</item> ????????<item?name="android:layout_marginRight">@dimen/marginSize</item> ????????<item?name="android:gravity">center</item> ????????<item?name="background">@drawable/btn_commit_select</item> ????</style>
btn_commit_select.xml <?xml?version="1.0"?encoding="utf-8"?> <selector?xmlns:android="http://schemas.android.com/apk/res/android"> <!--???View高亮?--> <item?android:state_focused="true"?android:drawable="@drawable/commit_btn_h"/> <item?android:state_pressed="true"?android:drawable="@drawable/commit_btn_h"/> <item?android:state_selected="true"?android:drawable="@drawable/commit_btn_h"/> <!--????View默認--> <item?android:drawable="@drawable/commit_btn_n"/> </selector>
commit_btn_h.xml
<?xml?version="1.0"?encoding="utf-8"?> <shape?xmlns:android="http://schemas.android.com/apk/res/android" ????android:shape="rectangle"> <!--實體顏色--> ????<solid?android:color="@color/mainColorH"/> <!--弧度--> ????<corners?android:radius="@dimen/radius"/> </shape>
commit_btn_n.xml
<?xml?version="1.0"?encoding="utf-8"?> <shape?xmlns:android="http://schemas.android.com/apk/res/android" ????android:shape="rectangle"> <!--實體顏色--> ????<solid?android:color="@color/mainColor"/> <!--弧度--> ????<corners?android:radius="@dimen/radius"/> </shape>
2021-02-08
1.????在 res\values\strings.xml 中添加如下字符串文本定義;
2.????在 activity_login.xml 下的 <Button/> 標簽中引入這個字符串文本,如下