Android 更换一个可拉拔部件,而不是另一个可拉拔部件
我使用多功能按钮这意味着一个按钮在不同的情况下,它有不同的反应。 如果没有拒绝。我使用了一个Drawable for Textcolor按钮,按钮的功能也会改变Drawable。但问题是输出不同。应该是什么颜色,而不是应该是什么颜色。颜色与我选择的颜色不同。看起来两个Drawable合并了。请指导我Android 更换一个可拉拔部件,而不是另一个可拉拔部件,android,drawable,Android,Drawable,我使用多功能按钮这意味着一个按钮在不同的情况下,它有不同的反应。 如果没有拒绝。我使用了一个Drawable for Textcolor按钮,按钮的功能也会改变Drawable。但问题是输出不同。应该是什么颜色,而不是应该是什么颜色。颜色与我选择的颜色不同。看起来两个Drawable合并了。请指导我 if (bsc.getText().toString().equals(getResources().getString(R.string.inotpaid))) {
if (bsc.getText().toString().equals(getResources().getString(R.string.inotpaid))) {
tfr.setText(R.string.select_pay_way);
tsc.setText(R.string.also);
bfr.setText(R.string.app_intro);
bsc.setText(R.string.site_way);
bth.setText(R.string.bank_way);
bth.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_style_trans));
bth.setTextColor(R.drawable.change_text_color);
}
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/blueyellows" android:state_pressed="true"/>
<item android:color="#ffffff"/>
</selector>
<Button
android:id="@+id/bth"
android:layout_width="220dp"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp"
android:background="@android:color/transparent"
android:text="@string/price_que"
android:textColor="@drawable/change_text_color_black"
android:textSize="15dp"
android:visibility="invisible" />
if(bsc.getText().toString().equals(getResources().getString(R.string.inotpaid))){
tfr.setText(R.string.select\u pay\u way);
tsc.setText(R.string.allow);
bfr.setText(R.string.app_intro);
bsc.setText(R.string.site\u-way);
bth.setText(R.string.bank_-way);
bth.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_style_trans));
bth.setTextColor(R.drawable.change\u text\u color);
}
您必须使用布尔值来切换按钮。根据该值,它可以更改功能。你可以这样做
private boolean isButtonPressed = false;
public void onClick(View v) {
if (isButtonPressed) {
isButtonPressed = false;
} else {
isButtonPressed = true;
}
}
现在,根据isButtonPressed的值,您可以为按钮提供不同的功能,如:
if(isButtonPressed) {
button.setBackground(Color.BLACK);
} else {
button.setBackground(Color.WHITE);
}
}
我希望这是有帮助的。你所说的
应该是什么颜色,而不是应该是什么颜色。颜色与我选择的颜色不同。似乎两个可绘制的颜色合并了。请指导我。
?在第二个可绘制的颜色中,颜色必须变为白色,但是颜色是灰色的你想根据按钮点击或者其他逻辑改变颜色吗?我的英语不好。我总是很难将自己的请求发送给其他人,反之亦然!但我试着用谷歌翻译