#android #layout #webview
#Android #макет #webview
Вопрос:
У меня есть следующий код, который работает, но не использует веб-экран моего макета.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webscreen);
String turl = getIntent().getStringExtra(URL);
Log.v(TAG, "Recipe url = " turl);
WebView webview = new WebView(this);
setContentView(webview);
webview.clearCache(true);
webview.loadUrl(turl);
Если я изменю строку setcontentview (webview) на setcontentview (R.layout.webscreen), мой макет загрузится, но веб-страница — нет.
Извините, я новичок.
С уважением,
Майк
Ответ №1:
Попробуйте это,
public class Main extends Activity {
WebView webview1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webview1 = (WebView)findViewById(R.id.webview01);
webview1.getSettings().setJavaScriptEnabled(true);
webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview1.getSettings().setBuiltInZoomControls(true);
webview1.setInitialScale(50);
webview1.loadUrl("http://www.mywebsite.com/");
}
}
xml-файл
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal">
<WebView android:layout_marginTop="60sp" android:id="@ id/webview01" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</ScrollView>
</LinearLayout>
Комментарии:
1. Спасибо за
webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true)
. Теперь отображается рамка оплаты на Lenovo Vibe Z2.