我正在为andorid写一份申请,我在更换按钮背景方面有困难。我有一个简单的按钮,当用户点击按钮时,改变背景。我想让按钮在用户再次点击时恢复到原来的状态。我不知道该怎么做,如果谁有一个请回复!
发布于 2015-08-26 04:50:21
使用android.R.drawable.btn_default将按钮更改为默认颜色
发布于 2015-08-26 18:02:49
@Howlett Logan :你可以尝试这样做,
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextButton"
/>然后
public boolean flag=true; // Global
Button buttonTest;
@Override
protected void onCreate(Bundle savedInstanceState)
{
buttonTest=(Button)findViewById (R.id.button);
buttonTest.setBackgroundResource(R.drawable.your_drawble);
buttonTest.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (flag)
{
buttonTest.setBackgroundResource(R.drawable.your_image_1);
}else
{
buttonTest.setBackgroundResource(R.drawable.your_image_2);
}
flag=!flag;
}
});
}https://stackoverflow.com/questions/32213721
复制相似问题