反彈此question:如何使用自定義webview和覆蓋功能?
我已經做了一個自定義webview稱爲FlingView
合併手勢事件。上述鏈接問題中的策略對我來說很好,我的活動佈局XML是好的:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.brianclements.android.WebViewActivity">
<net.brianclements.android.FlingView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_webview_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_webview_drawer_left" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_webview_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_webview_drawer_right" />
</android.support.v4.widget.DrawerLayout>
的onCreate()做到這一點:
setContentView(R.layout.activity_web_view);
,我已經用這種方法成功地加載:
mWebview = (FlingView) findViewById(R.id.webview);
現在的問題是當我嘗試覆蓋它裏面的功能:
mWebview = new FlingView(this, null) {
@Override
public void onLeftFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling left: ");
someDynamicObject.thatCantBeUsedStatically();
}
@Override
public void onRightFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling right: ");
anotherDynamicObject.thatCantBeUsedStatically();
}
};
那麼現在如何將mWebview
重新插入佈局?第一種鑄造方法非常簡單。但從我的研究,我相信它現在涉及一些充氣器的組合,findViewById()
,addView()
,removeView()
但我似乎無法弄清楚。這裏的任何想法?
這是優秀的;它教會了我如何正確實現一個聽衆。謝謝! – brianclements