I am trying to set the textsize and textcolor from the pagertitlestrip and cannot find a way to do it.
<android.support.v4.view.ViewPager
android:id="@+id/myPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/myStrip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
EDIT
main.xml
<android.support.v4.view.ViewPager
android:id="@+id/myPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
style="@style/PagerTitleStrip"
android:id="@+id/myStrip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
style.xml
<style name="PagerTitleStrip">
<item name="android:textAppearance">@style/PagerTitleStripTextAppearance</item>
</style>
<style name="PagerTitleStripTextAppearance">
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:textSize">14sp</item>
</style>
Pity that i didn't found a way to make it from AttributeSet, get a Resource NotFound or InvalidResource Exception.
textSize
is not available directly as XML property of view.PagerTitleStrip
.
However I managed to set it up indirectly using the style attribute as follows:
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
style="@style/viewPagerTitleStrip" <-- added style attribute here
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
/>
Then I defined the textSize
in styles.xml as follows:
<style name="viewPagerTitleStrip">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">14sp</item> <-- my desired text size
</style>
This worked for me.
from: http://developer.android.com/reference/android/support/v4/view/PagerTitleStrip.html
Set the color value used as the base color for all displayed page titles:
void setTextColor(int color)
Set the default text size to a given unit and value:
void setTextSize(int unit, float size)
looks like a no-brainer.
PagerTitleStrip titleStrip = (PagerTitleStrip) findViewById(R.id.titleStrip);
titleStrip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With