Why shouldn't I set layout
If I have a lot of TextViews serving as item labels, I thought I could extract everything that's common about them into a style, and in the layout use only
<TextView style="@style/label" android:text="Foo"/>
<TextView style="@style/label" android:text="Bar"/>
with style like:
<style name="label">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
But when I do this, it works fine on emulator and device, but the Android XML editor complains that "<TextView>" does not set the required layout_height attribute.
Is there some reason on why it is reporting this warning?
Have you tried to clean the project?
I am using also the same thing on some XML files for the width and the length. Here is an example working on my app, you can have a look:
<TextView
android:id="@+id/viewdescription"
android:textIsSelectable="true"
android:layout_below="@+id/rating_bar_view"
android:minLines="8"
style="@style/description" />
And the XML:
<style name="description">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:inputType">textMultiLine</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/Black</item>
<item name="android:layout_marginRight">8dp</item>
<item name="android:layout_marginLeft">8dp</item>
After a Build > Clean Project
attempt, I was still experiencing this same issue in the layout editor; a full restart of my IDE solved the problem for me.
I have tried this, its just working fine..
<EditText
android:id="@+id/edt_mobile_no"
style="@style/login_input_fields"
android:hint="@string/hint_mobile"
android:inputType="phone" />
Here below the style for the EditText
<style name="login_input_fields">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">40dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:background">@drawable/bg_curved_white_border</item>
<item name="android:paddingRight">10dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textColorHint">@color/underline</item>
<item name="android:textSize">16sp</item>
<item name="android:typeface">monospace</item>
</style>
链接地址: http://www.djcxy.com/p/79948.html
上一篇: Android Studio中的LinearLayout和FrameLayout多个错误
下一篇: 为什么我不应该设置布局