是否有一种简单的方法(可能是非编程的?)来使 WebView 中的文本大小与 TextView 中的文本大小相匹配?
我有一个(XML 指定的)TextView,它没有文本大小或外观属性:
<TextView
android:id="@+id/lblExerciseSummary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/lblWeekTitle"
android:textColor="@color/home_screen_text_colour"
android:paddingBottom="4dp"
android:paddingLeft="4dp" />
还有一个没有文本大小或外观属性的 WebView:
<WebView
android:id="@+id/wvTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/lblRunDescription"
android:layout_below="@+id/lblTest"
android:background="#00000000" />
当我将文本放入 TextView(使用 setText())并将 HTML 放入 WebView(使用 loadData() 并将文本本身放入 <p>
元素中,没有额外的 CSS/内联样式集),这两个 View 显示不同大小的文本(WebView 似乎默认为比 TextView 更大的大小。)
确保我的 WebView 文本在大小上始终与 TextView 文本匹配的最佳方法是什么,并且可能在其他外观上匹配——它甚至是相同的字体是否可能只是运气好?
我猜测 TextView 正在从主题/样式/设备设置中获取一些默认值,但我也猜测 WebView 有某种默认样式表,它可能不会被选取相同的设置?
最佳答案
马特,你可以尝试在你的 WebView
中使用方法 setTextZoom()
:
thisWB.getSettings().setTextZoom(thisTV.getTextSize());
thisWB
:您的WebView
thisTV
:您的 TexView
,您将从那里获取 WebView
请注意,setTextZoom(int textZoom)
方法是 API 级别 14(如果您正在为 Android 4.0+ 开发应用程序,请使用它)。
链接:WebSettings
关于android - 将 Android WebView 文本大小与 TextView 文本大小相匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8762449/