我正在android studio中编写一个应用程序,其中TextViews
和id
的所有属性都相同。因此,我在text
中声明了一种样式,如下所示:
style.xml
在我的<style name="thirdTextView" parent="TextAppearance.AppCompat">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/black</item>
<item name="android:layout_gravity">center_vertical</item>
</style>
中,我使用了以下样式:
activity_main.xml
但是我看不到布局的预览,但出现此错误:
<TextView
style="@style/thirdTextView"
android:text="@string/questionWeight"/>
如何解决这个问题?
答案 0 :(得分:2)
将您的TextViews更改为此;
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/thirdTextView"
android:text="@string/questionWeight"/>
布局文件中的每个小部件都需要height和width属性。希望这会有所帮助。