P.Vamsi
P.Vamsi

Reputation: 73

attribute (android:textSize="?android:attr/textAppearanceMedium") throws error

why does this attribute throw error "Binary XML file line #25: Error inflating class TextView"? my app crashed when i used the attribute to declare it to "?android:attr/textAppearanceMedium", but when i changed it to hard-coded "16sp" it worked without crashing. what is wrong with this attribute?

<i>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tan_background"
    android:minHeight="@dimen/list_item_height"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/list_item_height"
        android:layout_height="@dimen/list_item_height"
        android:background="@color/tan_background"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:id="@+id/textLayout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/list_item_height"
        android:orientation="vertical"
        android:paddingLeft="16dp">

        <TextView
            android:id="@+id/miwok_name"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:textColor="@android:color/white"
            android:textSize="?android:attr/textAppearanceMedium"
            android:textStyle="bold"
            android:gravity="bottom"
            tools:text="lutti"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/default_name"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:textColor="@android:color/white"
            android:textSize="?android:attr/textAppearanceMedium"
            tools:text="one"
            android:layout_weight="1"
            android:gravity="top"/>
    </LinearLayout>

</LinearLayout>
</i>

Upvotes: 2

Views: 11726

Answers (2)

Alex Chengalan
Alex Chengalan

Reputation: 8281

You should replace your textSize with textAppearance

android:textAppearance

Base text color, typeface, size, and style.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

textSize

Size of the text. Recommended dimension type for text is "sp" for scaled-pixels (example: 15sp).

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

Thats why your app gets crashed, hope it helps.

Upvotes: 1

SpiralDev
SpiralDev

Reputation: 7331

Replace

android:textSize=""?android:attr/textAppearanceMedium""

with this:

android:textAppearance="?android:attr/textAppearanceMedium"

Upvotes: 3

Related Questions