【发布时间】:2017-05-19 14:14:34
【问题描述】:
我的 XML 中有这个 Button:
<Button
android:id="@+id/button_message_me"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@drawable/ic_chat_white_48dp"
android:onClick="clickMessageMe"/>
但是,我想将ic_chat_white_48dp 的颜色从白色更改为蓝色。怎么改?
到目前为止我已经尝试过的:
阅读this 的帖子后,我尝试使用android:tint="@color/blue",但没有成功。
因此,考虑到我可能需要使用ImageButton 而不是Button(如answer 中所述),我在我的XML 中将Button 替换为ImageButton,但我得到了异常:
java.lang.RuntimeException:无法启动活动 组件信息{chat.knowme.knowme/chat.knowme.knowme.ShowProfileActivity}: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageButton 无法转换为 android.widget.Button
任何帮助将不胜感激。非常感谢!
更新:
崩溃是因为我在源代码中将ImageButton 转换为Button。我修复了它,现在不再崩溃了(感谢 Patel Pinkal 的回答)。
但是,即使使用ImageButton,颜色仍然保持不变
【问题讨论】:
-
发布你的
Button初始化代码 -
这个按钮没有初始化代码。每当我想显示/隐藏此按钮时,我都会使用
(Button) findViewById(R.id.button_message_me);。并为按钮编写了clickMessageMe方法。但是,一旦我启动活动,就会发生崩溃。 -
你在用什么
ImageButton或AppCompatImageButton?
标签: android icons material-design android-appcompat