我知道以前有人问过这个问题,但是我已经尝试了其他问题的所有“解决方案”,但我仍然无法实现我想要做的事情。我已经搜索和搜索,并尝试过。请原谅我。我只是想在我的 WebView 上方显示我的按钮行,以便它与我的应用程序中的其余活动保持一致(它们都在顶部有按钮行)。似乎我已经尝试了所有可能的布局组合,但无济于事。它在图形布局(Eclipse)中正确显示,但在手机和模拟器上它只显示 WebView、全屏、没有按钮......任何帮助将不胜感激!
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/menu_panel">
<ImageButton
android:id="@+id/bHomeMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="@drawable/menu_btn_hcu_light_blue"
android:src="@drawable/icon_menu_home"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="@style/ButtonText"
android:textSize="13sp"
android:text="Home" />
<ImageButton
android:id="@+id/bItsMe247Menu"
android:layout_toRightOf="@+id/bHomeMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="@drawable/menu_btn_selected_hcu_light_blue"
android:src="@drawable/icon_menu_login"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="@style/ButtonText"
android:textSize="13sp"
android:text="It'sMe" />
<ImageButton
android:id="@+id/bFindUsMenu"
android:layout_toRightOf="@+id/bItsMe247Menu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="@drawable/menu_btn_hcu_light_blue"
android:src="@drawable/icon_menu_find_us"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="@style/ButtonText"
android:textSize="13sp"
android:text="FindUs" />
<ImageButton
android:id="@+id/bEmailMenu"
android:layout_toRightOf="@+id/bFindUsMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="@drawable/menu_btn_hcu_light_blue"
android:src="@drawable/icon_menu_email"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="@style/ButtonText"
android:textSize="13sp"
android:text="Email" />
<ImageButton
android:id="@+id/bRatesMenu"
android:layout_toRightOf="@+id/bEmailMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="@drawable/menu_btn_hcu_light_blue"
android:src="@drawable/icon_menu_rates"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="@style/ButtonText"
android:textSize="13sp"
android:text="Rates" />
</LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wvItsMe"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
编辑:这是我的java代码,下面有一个注释:
package com.dummyapp.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.dummyapp.app.SimpleGestureFilter.SimpleGestureListener;
public class ItsMe247 extends Activity implements SimpleGestureListener{
private SimpleGestureFilter detector;
private WebView itsMeLogin;
// ImageButton menuHome, menuFindUs, menuEmail, menuRates;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.itsme247);
// menuHome = (ImageButton)findViewById(R.id.bHomeMenu);
// menuFindUs = (ImageButton)findViewById(R.id.bFindUsMenu);
// menuEmail = (ImageButton)findViewById(R.id.bEmailMenu);
// menuRates = (ImageButton)findViewById(R.id.bRatesMenu);
detector = new SimpleGestureFilter(this,this);
itsMeLogin = new WebView(this);
Toast.makeText(this, "Just Swipe To Exit", Toast.LENGTH_LONG).show();
itsMeLogin.getSettings().setJavaScriptEnabled(true); // JavaScript enabled
getWindow().requestFeature(Window.FEATURE_PROGRESS); // Show progress bar of page loading
final Activity itsMeActivity = this;
itsMeLogin.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress){
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
itsMeActivity.setProgress(progress * 100);
}
});
itsMeLogin.setWebViewClient(new WebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(itsMeActivity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
itsMeLogin.loadUrl("http://www.google.com");
setContentView(itsMeLogin);
// itsMeLogin.setWebViewClient(new WebViewClient() {
// @Override
// public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
// return super.shouldOverrideUrlLoading(view, url);
// }
// });
//******************* MENU BUTTONS START HERE ********************************************************//
// menuRates.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent ratesIntent = new Intent(ItsMe247.this, Rates.class);
// ItsMe247.this.startActivity(ratesIntent);
//
// }
//
// });
//
//
// menuFindUs.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent contactIntent = new Intent(ItsMe247.this, Contact.class);
// ItsMe247.this.startActivity(contactIntent);
//
// }
// });
//
// menuEmail.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent emailIntent = new Intent(ItsMe247.this, Email.class);
// ItsMe247.this.startActivity(emailIntent);
//
//
// }
// });
//
// menuHome.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent itsMeIntent = new Intent(ItsMe247.this, MainActivity.class);
// ItsMe247.this.startActivity(itsMeIntent);
// }
// });
//***************************** MENU BUTTONS END HERE ********************************************************//
}//end onCreate method
@Override
public boolean dispatchTouchEvent(MotionEvent me){
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
public void onSwipe(int direction) {
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
Intent funIntent = new Intent(ItsMe247.this, MainActivity.class);
ItsMe247.this.startActivity(funIntent);
//ItsMe247.this.finish();
break;
case SimpleGestureFilter.SWIPE_LEFT:
Intent funIntent2 = new Intent(ItsMe247.this, Contact.class);
ItsMe247.this.startActivity(funIntent2);
//ItsMe247.this.finish();
break;
case SimpleGestureFilter.SWIPE_DOWN:
break;
case SimpleGestureFilter.SWIPE_UP:
break;
}
}//end onSwipe method
public void onDoubleTap() {
}
}
我已经注释掉了所有的菜单按钮(我试图在 webview 上方显示的按钮),直到我最终让它们通过 xml 显示。但是,每当我取消注释按钮及其侦听器时,应用程序会在尝试进入此活动时崩溃。