Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The library project has a Customview <code>Spinnerbutton</code> which extends TextView (in you case it may be different. For testing i extended TextView).</p> <p>Now if i understand correctly this view is used in android project and you need to set the style to that custom view which can be done as below. </p> <p>Use the style in android library project as the parent style and then customize the style in android project <code>styles.xml</code>. Now set the style to the customview.</p> <pre><code>package com.example.customviewattributes.p1; import com.example.customviewattributes.R; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.widget.TextView; public class Spinnerbutton extends TextView{ public Spinnerbutton(Context context) { this(context, null); } public Spinnerbutton(Context context, AttributeSet attrs) { this(context, attrs, 0); } public Spinnerbutton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // real work here TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.Spinnerbutton, 0, 0 ); try { int textStyleId = a.getResourceId( R.styleable.Spinnerbutton_myTextAppearence, -1); Log.i("................ID is",""+textStyleId); // to make sure i logged the id this.setText("hello"); this.setTextAppearance(context,textStyleId); // set the style to text } finally { // release the TypedArray so that it can be reused. a.recycle(); } } } </code></pre> <p>styles.xml</p> <pre><code>&lt;resources&gt; &lt;style name="AppBaseTheme" parent="android:Theme.Light"&gt; &lt;item name="android:textViewStyle"&gt;@style/QText&lt;/item&gt; &lt;/style&gt; &lt;style name="AppTheme" parent="AppBaseTheme"&gt; &lt;/style&gt; &lt;style name="QText" parent="@android:style/TextAppearance.Medium"&gt; &lt;item name="android:textSize"&gt;20sp&lt;/item&gt; &lt;item name="android:textColor"&gt;@color/ccolor&lt;/item&gt; &lt;item name="android:textStyle"&gt;bold&lt;/item&gt; &lt;item name="android:typeface"&gt;sans&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>attrs.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;declare-styleable name="Spinnerbutton"&gt; &lt;attr name="myTextAppearence" format="reference" /&gt; &lt;/declare-styleable&gt; &lt;/resources&gt; </code></pre> <p>colors.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;color name="ccolor"&gt;#ff3232&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>All the above in library project.</p> <p>Now in Another Android Project</p> <p>activity_main.xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" &gt; &lt;com.example.customviewattributes.p1.Spinnerbutton android:id="@+id/sbp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>In MainActivity.java</p> <pre><code>setContentView(R.layout.activity_main); com.example.customviewattributes.p1.Spinnerbutton cv = (Spinnerbutton) findViewById(R.id.sbp); cv.setTextAppearance(this,R.style.QText1); cv.setText("hello"); </code></pre> <p>styles.xml</p> <pre><code>&lt;resources&gt; &lt;style name="AppBaseTheme" parent="android:Theme.Light"&gt; &lt;item name="android:textViewStyle"&gt;@style/QText&lt;/item&gt; &lt;/style&gt; &lt;style name="AppTheme" parent="AppBaseTheme"&gt; &lt;/style&gt; &lt;style name="QText1" parent="@style/QText"&gt; &lt;item name="android:textSize"&gt;50sp&lt;/item&gt; &lt;item name="android:textColor"&gt;@color/ccolor&lt;/item&gt; &lt;item name="android:textStyle"&gt;bold&lt;/item&gt; &lt;item name="android:typeface"&gt;sans&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>colors.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;color name="ccolor"&gt;#4F47B7&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>Snap</p> <p>This is for android project</p> <p><img src="https://i.stack.imgur.com/OOLbE.png" alt="enter image description here"></p> <p>Now if i run library project as a normal android project</p> <p>Snap</p> <p><img src="https://i.stack.imgur.com/XAEYT.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload