【发布时间】:2012-03-17 21:14:45
【问题描述】:
在我的应用程序中,我想将 8 dip 的顶部和底部边距设置为 textview。所以如果我这样做 -
<TextView
android:id="@+id/tv_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/settings_plain_text"/>
在样式内容所在的地方可以正常工作-
<style name="settings_plain_text">
<item name="android:layout_marginTop"> 8dip </item>
<item name="android:layout_marginBottom"> 8dip </item>
<item name="android:textSize"> 18sp </item>
</style>
但是当我以编程方式将相同的样式应用于该文本视图时 -
textview.setTextAppearance(context, R.style.settings_plain_text);
它没有显示我在样式中设置的顶部和底部边距。 请帮忙。
【问题讨论】:
-
android set style in code 的可能副本;
setTextAppearance()仅顾名思义更改文本外观,不包括边距。设置 View 的样式更复杂,并且在我在这里提到的问题中作为重复项链接(因为它基本上是相同的基础问题)。 -
@corsair992 您实际上应该将该问题评论为可能重复,因为该问题是在该问题之前 3 年提出的。 :)
-
样式是在视图膨胀期间应用的(非常简化),因此您所要求的全部内容是不可能的。
-
@Rajkiran:另一个问题更笼统,并提供了一些潜在的建议。请参阅Opinions on closing an older question as a duplicate of a newer question 上的元答案