我知道有很多与我的问题类似的问题和一些答案,但是我已经尝试了所有无法在屏幕上完美设置自定义WebView的问题。
我已经创建了一个自定义WebView:
public class ContentView extends WebView {
Context mContext;
MenuItem menuItem;
String name;
URL url;
public ContentView(Context context) {
super(context);
}
public void loadContent(Context context, MenuItem item) {
menuItem = item;
name = item.name;
url = item.url;
mContext = context;
String token = SharedPreferencesManager.getToken(mContext);
Map<String, String> extraHeaders = new HashMap<>();
extraHeaders.put("Authorization", "Bearer: " + token);
loadUrl(url.toString(), extraHeaders);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
我要在屏幕上添加多个实例:
final MenuItem menuItem = item;
ContentView contentView = new ContentView(this);
contentView.setId(View.generateViewId());
contentView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
contentFinishedLoaded(menuItem);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
// Adds the content to layout
ConstraintLayout layout = (ConstraintLayout)findViewById(R.id.activityMainConstraint);
ConstraintSet set = new ConstraintSet();
layout.addView(contentView);
set.clone(layout);
set.connect(contentView.getId(), ConstraintSet.TOP, R.id.toolBar, ConstraintSet.BOTTOM, 0);
set.connect(contentView.getId(), ConstraintSet.BOTTOM, R.id.navigationBar, ConstraintSet.TOP, 0);
set.connect(contentView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 0);
set.connect(contentView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
set.applyTo(layout);
// Loading content
contentView.loadContent(this, menuItem);
这是我要求的AppManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dbl">
<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=".LoginActivity"></activity>
<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>
我尝试过:
我的网络视图严格是程序化的,因此不涉及xml。
答案 0 :(得分:0)
转到android清单文件并检查@theme属性。您需要将@theme更改为默认样式。
请分享您的清单代码以更好地理解。