如何在webview中启用ActionBar。我的当前代码直接加载到网页浏览器并跳过所有其他的activity逻辑,但我不确定原因。
Main Activity(主要活动)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("My Page");
actionBar.setDisplayShowHomeEnabled(false);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl(http://www.google.com);
}
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" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dip"
/>
</LinearLayout>
我还尝试创建对话框来显示Webview,但也没有成功。
谢谢!
setContentView
之前调用setTheme
即可。但是,如果您使用一些旧版本的自定义操作栏,则这将无济于事。 - vortexwolf