first commit
This commit is contained in:
parent
3018e73f4a
commit
ea5084c580
|
@ -2,6 +2,8 @@ package com.pxkj.jwzs;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -26,13 +28,24 @@ public class FirstActivity extends BaseActivity {
|
|||
setContentView(R.layout.activity_main); // 必须先加载布局,再初始化控件
|
||||
|
||||
// 初始化TextView(关键!绑定布局中的tv_api_result)
|
||||
tvApiResult = findViewById(R.id.tv_api_result);
|
||||
// tvApiResult = findViewById(R.id.tv_api_result);
|
||||
|
||||
// Button btnTestApi = findViewById(R.id.btn_test_api);
|
||||
// btnTestApi.setOnClickListener(v -> {
|
||||
// tvApiResult.setText("测试中..."); // 此时tvApiResult已初始化,不会空指针
|
||||
// fetchData();
|
||||
// });
|
||||
|
||||
|
||||
WebView webView = findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true); // 启用JS
|
||||
webView.setWebViewClient(new WebViewClient()); // 防止跳转浏览器
|
||||
webView.loadUrl("http://218.92.207.242:50022/"); // 加载H5地址
|
||||
webView.getSettings().setDomStorageEnabled(true);
|
||||
webView.clearCache(true); // 清除缓存
|
||||
webView.getSettings().setUseWideViewPort(true);
|
||||
webView.getSettings().setLoadWithOverviewMode(true);
|
||||
|
||||
Button btnTestApi = findViewById(R.id.btn_test_api);
|
||||
btnTestApi.setOnClickListener(v -> {
|
||||
tvApiResult.setText("测试中..."); // 此时tvApiResult已初始化,不会空指针
|
||||
fetchData();
|
||||
});
|
||||
|
||||
init(); // 调用父类方法
|
||||
}
|
||||
|
@ -40,8 +53,8 @@ public class FirstActivity extends BaseActivity {
|
|||
|
||||
private void fetchData() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://50.146.63.127:82/app/api/")
|
||||
// .baseUrl("http://218.92.207.242:50021/gwgl/")
|
||||
// .baseUrl("http://50.146.63.127:82/app/api/")
|
||||
.baseUrl("http://218.92.207.242:50021/gwgl/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
ApiService service = retrofit.create(ApiService.class);
|
||||
|
|
|
@ -6,28 +6,33 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_test_api"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="测试接口"
|
||||
android:layout_marginTop="32dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_test_api"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="测试接口"-->
|
||||
<!-- android:layout_marginTop="32dp"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toTopOf="parent" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_api_result"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:padding="16dp"
|
||||
android:background="#F0F0F0"
|
||||
android:text="点击按钮测试接口..."
|
||||
android:textColor="#333333"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_test_api" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tv_api_result"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="32dp"-->
|
||||
<!-- android:layout_marginHorizontal="16dp"-->
|
||||
<!-- android:padding="16dp"-->
|
||||
<!-- android:background="#F0F0F0"-->
|
||||
<!-- android:text="点击按钮测试接口..."-->
|
||||
<!-- android:textColor="#333333"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/btn_test_api" />-->
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue