小编Ali*_*Ali的帖子

Android ImageButton - 单击按钮时如何更改图像?

如果单击按钮,我想打开 wifi 并更改 ImageButton 的图像,但我不知道如何更改它

我也尝试过如何在每次点击时更改按钮的图像?但不起作用:

boolean isPressed=false
button.setOnClickListener(buttonListener);

OnClickListener buttonListener= new OnClickListener() {
@Override
public void onClick(View v) {
    if(isPressed){
    button.setBackgroundResource(R.drawable.icon1);
    }else{
    button.setBackgroundResource(R.drawable.icon2);
    }
    isPressed=!isPressed;
}};
Run Code Online (Sandbox Code Playgroud)

当我编写上面的代码时,android studio 显示:无法解析符号setOnClickListener

我还创建了一个button_wifi_selector xml,它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<item android:drawable="@drawable/wifi_on"
    android:state_pressed="true" />
<item android:drawable="@drawable/ic_launcher"
    android:state_focused="true" />
<item android:drawable="@drawable/wifi" />

</selector>
Run Code Online (Sandbox Code Playgroud)

在我的活动中我有这个

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton_wifi"
    android:layout_below="@+id/toggleButton_wifi"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:onClick="turnOffWifiDemo"
    android:src="@drawable/button_wifi_selector" />
Run Code Online (Sandbox Code Playgroud)

但它没有做,我想要什么有人可以帮助我吗?谢谢

编辑:它适用于第一个代码。我只需从 xml 中的 ImageButton 中删除 onClick 但是:当我启动应用程序时,他正在第二次更改图片。之后他每次都会改变

sdk android button imagebutton

5
推荐指数
1
解决办法
6万
查看次数

Typo3 8.3.1无法访问远程资源http://repositories.typo3.org/mirrors.xml.gz

我无法在TYPO3中更新扩展名列表.这是他给我的错误:

Could not access remote resource http://repositories.typo3.org/mirrors.xml.gz.
Run Code Online (Sandbox Code Playgroud)

我正在运行Windows 10.在XAMPP v3.2.2(PHP 7.0.9)上运行的TYPO3 8.3.1

我尝试了几件事,从编辑php.ini到编辑httpd.conf,但对我来说没什么用.

谢谢你的帮助!

php xampp typo3 windows-10

4
推荐指数
1
解决办法
1491
查看次数

标签 统计

android ×1

button ×1

imagebutton ×1

php ×1

sdk ×1

typo3 ×1

windows-10 ×1

xampp ×1