I am newbie in android development, I am trying to create my custom view right now. I have faced with a lot of problems. I have solved some of them, but the most difficult to understand for is attributes. Let's take sample xml file with attributes
<declare-styleable name="ViewPagerIndicator">
<!-- Style of the circle indicator. -->
<attr name="vpiCirclePageIndicatorStyle" format="reference"/>
<!-- Style of the icon indicator's views. -->
<attr name="vpiIconPageIndicatorStyle" format="reference"/>
<!-- Style of the line indicator. -->
<attr name="vpiLinePageIndicatorStyle" format="reference"/>
<!-- Style of the title indicator. -->
<attr name="vpiTitlePageIndicatorStyle" format="reference"/>
<!-- Style of the tab indicator's tabs. -->
<attr name="vpiTabPageIndicatorStyle" format="reference"/>
<!-- Style of the underline indicator. -->
<attr name="vpiUnderlinePageIndicatorStyle" format="reference"/>
</declare-styleable>
<attr name="centered" format="boolean" />
<attr name="selectedColor" format="color" />
<attr name="strokeWidth" format="dimension" />
<attr name="unselectedColor" format="color" />
<declare-styleable name="CirclePageIndicator">
<attr name="centered" />
<attr name="fillColor" format="color" />
<attr name="pageColor" format="color" />
<attr name="android:orientation"/>
<attr name="radius" format="dimension" />
<attr name="snap" format="boolean" />
<attr name="strokeColor" format="color" />
<attr name="strokeWidth" />
<attr name="android:background"/>
</declare-styleable>
<declare-styleable name="LinePageIndicator">
<attr name="centered" />
<attr name="unselectedColor" />
<attr name="selectedColor" />
<attr name="lineWidth" format="dimension" />
<attr name="strokeWidth" />
<attr name="gapWidth" format="dimension" />
<attr name="android:background"/>
</declare-styleable>
- What does reference format mean, I cannot still understand what does this format mean, what I've found that it can be used with drawables also I seen that can be used with themes. Please give good example where it can be useful and what is the main purpose of this format type. In preceding example it is used for style, but I don't understand how can I use this in my xml file where I am going to use custom view.
<com.viewpagerindicator.CirclePageIndicator android:id="@+id/indicator" android:padding="10dip" android:layout_height="wrap_content" android:layout_width="wrap_content" custom:auto_cycle="true" custom:pageColor="@color/abc_background_cache_hint_selector_material_dark" />
-
Each
declare-styleable name="Name of custom view"
line, as I can understand, used for separate custom view, we can see this in the example. But what is the purpose of<declare-styleable name="ViewPagerIndicator">
, I haven't found any view in this lib with such name and this stylable is include my first question (reference attribute). -
If attribute declared out of declare-stylable it means that it is in several view and not to duplicate code in each view common attributes are placed outside. Am I right ?
Please help, I have spent a day trying to find any tutorials or documentation. Official documentation is very poor. I think a lot of newbies will be grateful for explaining this topic.
Please help to understand this, the most important question is about references (first qustion) <attr name="vpiCirclePageIndicatorStyle" format="reference"/>
what is this , how to use this, where it is declared ?
Also I found another example used in another lib
<declare-styleable name="Themes">
<attr name="SliderStyle" format="reference"/>
<attr name="PagerIndicatorStyle" format="reference"/>
</declare-styleable>
I cannot understand this at all. Please help, you are my last hope.
Aucun commentaire:
Enregistrer un commentaire