最近,我将应用中的 compileSdkVersion
和 targetSdkVersion
从 27 更新为 28。我在一个屏幕中使用 Webview
只是为了显示对齐的文本。
这是代码
WebView webView = findViewById(R.id.webView);
String text = "Lorem ipsum dollar sit amet. Lorem ipsum dollar sit amet. Lorem ipsum dollar sit amet. Lorem ipsum dollar sit amet. Lorem ipsum dollar sit amet.";
String contentStr = String.valueOf(Html
.fromHtml("<![CDATA[<body style=\"text-align:justify;color:#80000000; \"><i><small>"
+ text
+ "</small></i></body>]]>"));
webView.loadDataWithBaseURL(null, contentStr, "text/html", "utf-8", null);
当我将 SDK 更新到 28 时,它什么也没有显示。 SDK为28时的输出
我尝试过 webView.loadData(contentStr, "text/html", "utf-8");
但没有结果。
请帮忙。
谢谢。
最佳答案
在 AS 中运行示例代码,一切似乎都正常。
Gradle :
android {
compileSdkVersion 28
defaultConfig {
applicationId "stackoverflow.tomerpacific.com.so"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}
关于Android webview 空白 - Android 28 SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53541419/