私はプログラムのさまざまな部分に多くのWebViewを持っていますが、これらのWebViewは相互に違いないので、必要な設定でカスタムWebViewを作成したいのです。現在のところ、WebViewは表示されませんが、エラーはありません。私は何か間違っているのですか?カスタムWebViewを作成する
public class MyWebView extends WebView {
MyWebView mMyWebView;
public MyWebView(Context context) {
super(context);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyWebView initView(Context context){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyWebView view = (MyWebView) inflater.inflate(R.layout.custom_webview, this);
view.getSettings().setJavaScriptEnabled(true) ;
view.getSettings().setUseWideViewPort(true);
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setDomStorageEnabled(true);
return view;
}
}
custom_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/custom_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
MainActivity:
public class MainActivity extends AppCompatActivity {
MyWebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = new MyWebView(MainActivity.this);
mWebView = mWebView.initView(MainActivity.this);
mWebView = (MyWebView) findViewById(R.id.web_view);
}
@Override
protected void onResume() {
mWebView.loadUrl("https://www.google.com/");
}
}
main_activity.xml:
<com.mypack.webview.MyWebView
android:id="@+id/web_view"
android:layout_below="@+id/start_URL"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
でそれを呼び出しますか –
は、私は、私はMainActivityに<:layout_width = "wrap_content" アンドロイド:layout_height = "wrap_content" アンドロイド:テキストは= "START" アンドロイド:ID = "@ + ID/START_URL" /ボタン アンドロイド>のボタンを持っていると思うん – Delphian
layout_below属性を削除してみることができますか? –