我有一个问题我正在创建一个应用程序网页视图以获取和网站上的游戏商店。
问题是它有一个下拉菜单html5 + jquery + css3。当我旋转智能手机时,网络会刷新。
这是我的代码Android Studio 3.0:
活动xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.icarosnet.icarosnetsa.IcarosWeb">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wv"
/>
</android.support.constraint.ConstraintLayout>
Main.Java
package com.icarosnet.icarosnetsa;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class IcarosWeb extends AppCompatActivity {
WebView wv ;
@Override
public void onBackPressed(){
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_icaros_web);
wv= (WebView) findViewById(R.id.wv);
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl("https://icarosnet.com");
wv.setWebViewClient(new WebViewClient());
}
@Override
protected void onSaveInstanceState(Bundle outState ){
super.onSaveInstanceState(outState);
wv= (WebView) findViewById(R.id.wv);
wv.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
wv= (WebView) findViewById(R.id.wv);
wv.restoreState(savedInstanceState);
}
}
Xml Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.icarosnet.icarosnetsa">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".IcarosWeb">
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
不尊重ajax加载的内容。
如何防止刷新并调整视图大小;或者我怎样才能只显示肖像并阻挡视图。
答案 0 :(得分:0)
<activity android:name=".TestActivity"
android:screenOrientation="portrait">
write this line and show it only portrait
答案 1 :(得分:0)
您只需在android:screenOrientation = "potrait"
文件的activity
标记内添加manifest
,即使电话被轮换,您的Activity
也无法轮播到landscape
。
答案 2 :(得分:0)
<activity
android:name="YourActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"/>
答案 3 :(得分:0)
@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
wv.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
wv.restoreState(savedInstanceState);
}
答案 4 :(得分:0)
试试这个: 它为WebView保存了onPause状态。
@Override
public void onPause() {
super.onPause();
webViewBundle = new Bundle();
wv.saveState(webViewBundle);
}
添加OnCreate:
if (webViewBundle == null) {
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl("https://icarosnet.com");
} else {
wv.restoreState(webViewBundle);
}
*假设将为该类声明wv
答案 5 :(得分:0)
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"><intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>