网站以Android应用程序打开,但无法互动

时间:2018-09-22 08:13:20

标签: android webview android-webview apk

所以我尝试使用android studio将正在处理的网站转换为android应用

应用程序构建成功,没有错误,在单击时会打开,但保持静态。我无法与它互动。 它只停留在主页上,没有交互。 无法向上/向下/向左/向右滑动 布局不正确 无法点击搜索框 主站点确实适应不同的屏幕尺寸

你能帮我诊断吗?

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">

<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView" />

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    </ListView>




</RelativeLayout>

MainActivity.java

package tech.radhelper.radhelpertech;

  import android.app.ListActivity;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;


 public class MainActivity extends ListActivity {
      private WebView myWebView;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myWebView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.loadUrl("https://radhelper.tech/");
    myWebView.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
    if(myWebView.canGoBack()) {
        myWebView.goBack();
    } else
        super.onBackPressed();

   }

}

AndroidManifest.xmml

 <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="tech.radhelper.radhelpertech">
     <uses-permission android:name="android.permission.INTERNET"></uses- 
 permission>

<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=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

 </manifest>

1 个答案:

答案 0 :(得分:1)

我通过将ListActivity更改为AppCompatActivity使其工作

然后更改activity_main.xml

我使用的代码是:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">

  <WebView
    android:id="@+id/webView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></ListView>

 </RelativeLayout>

我包装内容,而不是填充/匹配父项。

感谢Abhinav Gupta的帮助。。干杯!