我知道之前已经问过这个问题,但是我已经尝试了其他问题的每一个“解决方案”,但我仍然无法实现我想要做的事情。我搜索并搜索过,尝试过并尝试过。请原谅我。我只是想在我的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显示它们。但是,每当我取消注释按钮及其听众时,应用程序在尝试进入此活动时崩溃。
答案 0 :(得分:0)
您的代码没有使用您的XML布局,您在代码中创建自己的WebView并将其设置为视图,因此它完全绕过您的XML。
我在这里提供了一些应该让它发挥作用的变化。要特别注意setContentView行和以下行,这些都是使用XML布局的。您可能需要更改布局的名称(R.layout.whatever)和webview id(R.id.webview)。我把它放在这里可能有一些解析错误,可能错过了一个结束括号。为了简单起见,我删除了大部分已注释掉的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.xmlLayout );
itsMeLogin = (WebView)findViewById( R.id.webview );
detector = new SimpleGestureFilter(this,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");
}
这也是来自类似布局的我的XML文件,尽管你的可能会使用已编辑的代码。
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:columnCount="3"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<EditText
android:ems="4"
android:imeOptions="actionNext"
android:inputType="number"
android:layout_gravity="center_horizontal"
android:maxLength="4"
android:selectAllOnFocus="true"
/>
<EditText
android:ems="4"
android:imeOptions="actionDone"
android:inputType="textCapCharacters|textNoSuggestions"
android:layout_gravity="center_horizontal"
android:maxLength="3"
android:selectAllOnFocus="true"
/>
<Button android:id="@+id/submit"
/>
<WebView android:id="@+id/webview"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:layout_height="0dp"
android:layout_width="0dp"
/>
</GridLayout>