如果单击一个按钮,我想显示三个图像按钮以显示Web视图。但是,当我通过线性布局创建三个图像按钮时,它不正常,因为我想显示我是否单击图像按钮菜单下的按钮。但是,现在,它将进入新的窗口。
我的webview.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/imageButtonHomeSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_home_config"
android:onClick="imageButtonHomeSelector"
/>
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp" />
</RelativeLayout>
my mainactivity.java
public class MainActivity extends Activity {
private Button Homebutton, LoginButton, SettingButton;
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
startActivity(intent);
addListenerHomeButton();
// addListenerLoginButton();
// addListenerSettingButton();
}
public void addListenerHomeButton() {
Homebutton = (Button) findViewById(R.id.imageButtonHomeSelector);
Homebutton.setFocusable(true);
Homebutton.setFocusableInTouchMode(true);
Homebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
startActivity(intent);
}
});
}
public void addListenerLoginButton() {
LoginButton = (Button) findViewById(R.id.imageButtonLoginSelector);
// LoginButton.setFocusable(true);
LoginButton.setFocusableInTouchMode(true);
LoginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
});
}
public void addListenerSettingButton() {
SettingButton = (Button) findViewById(R.id.imageButtonSettingSelector);
SettingButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), SettingActivity.class);
startActivity(intent);
}
});
}
}
答案 0 :(得分:1)
您要做的第一件事就是从onCreate
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
// You are starting the Activity always without doing anything else
//Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
//startActivity(intent);
addListenerHomeButton();
// addListenerLoginButton();
// addListenerSettingButton();
}
然后您就可以点击按钮(如果可见)。
答案 1 :(得分:0)
您可以为触发按钮单击操作的三个按钮中的每个按钮设置onClick。