Why is the sample used? when linking to the list of styles SeparatorTextViewStyle?

I want to use the style of Android libraries. I think I should use @(Case 2) for the attribute style, but I saw a sample from the site it uses ?(Case 1). I do not know why.

Does the Android library have both a named resource listSeparatorTextViewStyle and a listSeparatorTextViewStyle attribute? Yes, I found a style called listSeparatorTextViewStyle in the system android lib attrs.xml, but where can I find the named listSeparatorTextViewStyle resource?

Here is the code and effect

Case 1

<TextView
    android:id="@+id/dialog_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    style="?android:attr/listSeparatorTextViewStyle"  
/>

Case1.GIF

Case 2

<TextView
    android:id="@+id/dialog_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    style="@android:attr/listSeparatorTextViewStyle"  
/>

Case2.GIF

+4
source share
2 answers

Link to resource attributes:

  • R.java, R.drawable.myimage
  • , XML, @drawable/myimage

:

  • A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."

  • To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@), use a question-mark (?), and the resource type portion is optional.

  • ?[<package_name>:][<resource_type>/]<resource_name>

EX::

   <EditText id="text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="?android:textColorSecondary"
    android:text="@string/hello_world" />
  • Here, the android:textColor attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary style attribute as the value for android:textColor in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary)—you can exclude the attr type.

:: Android Docs -

+2

!

R.stylable. :

@[+][package:]type:name ?[package:][type:]name.

, :

XML:

@[<package_name>:]<resource_type>/<resource_name>
  • <package_name> - , ( )
  • <resource_type> R
  • <resource_name> - , android: name XML ( ).

, , at (@) (?), . :

?[<package_name>:][<resource_type>/]<resource_name>

: @ XML ? style. , " " .

0

All Articles