为什么当我按下按钮时没有打开 webviewer?

why doesnt this open the webviewer when i press the button?

所以我有这个按钮,我希望它在按下按钮时打开一个网络查看器。

这是 xml 按钮所在的位置

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
    android:id="@+id/signIn"
    android:layout_width="match_parent"
    android:layout_height="61dp"
    android:src="@drawable/signin"
    android:textAlignment="center" />

</LinearLayout>

这里是点击按钮的 class 代码

public class SignIn extends Activity {
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    img = (ImageView) findViewById(R.id.signIn);
    signIn();

}
public void signIn() {
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(SignIn.this, WebViewActivity.class);
            startActivity(intent);
        }
    });
}
}  

这里是我 webviwer.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/webView1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />  

这是网络查看器 class

public class WebViewActivity extends Activity{

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://www.google.com");
}
}

当点击没有任何反应时,我还编辑了清单以访问互联网

稍作更正。在 XML 中,您使用的是 "ImageButton",但在 java 文件中,您使用的是 "ImageView".

<ImageView
android:id="@+id/signIn"
android:layout_width="match_parent"
android:layout_height="61dp"
android:src="@drawable/signin"
android:textAlignment="center" />

我认为在 XML ImageButton 和 java 文件中写入通过 id 搜索 ImageView 是错误的。

使用 ImageView 或 ImageButton!

如果你想使用 imageView,请不要忘记使其可点击。