android-target-tooltip
android-target-tooltip copied to clipboard
simple way to set the text color?
When using a custom style for the popup you may want to set the text color too. For now this seems only possible with creating a custom layout with the appropriate styling and setting it as custom view. Any chance to give the default textview a style that can be overwritten? Or am I missing something obvious?
The easiest way I have found to change the text color is, as you said, changing the custom view.
It wasn't so difficult.
I just copied the tooltip_textview.xml of this library, added it to my project and added one line of code: android:textColor="@color/myColor"
. Then I have set the custom view to the Builder with this code .withCustomView(R.layout.tooltip_textview, false)
.
I just hit this snag as well, where the custom style for the tooltip doesn't seem to respect android:textColor
. Rather than use a custom view and lose the nice pointed arrow that comes with the built-in view, I did the following to make my tooltip's text white:
// Build your tooltip and show it first, then...
final View tooltipView = TooltipManager.getInstance().get(idUsedToCreateTooltip);
final TextView tooltipTextView = (TextView) tooltipView.findViewById(android.R.id.text1);
tooltipTextView.setTextColor(getResources().getColor(android.R.color.white));
Just add
new Tooltip.Builder(101).withStyleId(R.style.ToolTipLayoutCustomStyle)
and in your style.xml you can set bold|italic or change textColor too
<style name="ToolTipLayoutCustomStyle">
<item name="ttlm_padding">20dip</item>
<item name="ttlm_strokeColor">#ffe5a000</item>
<item name="ttlm_backgroundColor">#ffe5c700</item>
<item name="ttlm_strokeWeight">1dip</item>
<item name="ttlm_cornerRadius">10dip</item>
<item name="ttlm_overlayStyle">@style/ToolTipOverlayCustomStyle</item>
<item name="android:textAppearance">@style/ToolTipTextStyle</item>
</style>
<style name="ToolTipTextStyle">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">@color/black_color</item>
</style>
<style name="ToolTipOverlayCustomStyle">
<item name="android:color">@color/white_color</item>
<item name="ttlm_repeatCount">1</item>
<item name="ttlm_duration">600</item>
<item name="android:alpha">0.2</item>
<item name="android:layout_margin">8dp</item>
</style>
maybe this is missing in README.md
It was very late but simple and neat way is just override textcolor only.
<style name="ToolTipLayoutHoianStyle" parent="ToolTipLayoutDefaultStyle">
<item name="android:textAppearance">@style/ToolTipTextStyle</item>
</style>
<style name="ToolTipTextStyle">
<item name="android:textColor">@color/white</item>
</style>
@Desno365 Can you please share the example using .withCustomView
? For some reason, the tooltip doesn't pick anything else other than the XML attributes that were already there in tooltip_textview
.
@rohan20 I'm sorry but I commented on here 4 years ago. I don't even remember for what I used this library.
See this: https://github.com/sephiroth74/android-target-tooltip/blob/master/xtooltip/src/main/java/it/sephiroth/android/library/xtooltip/Tooltip.kt#L167
TooltipLayout_ttlm_textStyle
So using:
<style name="ToolTipLayoutDefaultStyle">
<item name="ttlm_padding">30dp</item>
<item name="ttlm_strokeColor">#2B3339</item>
<item name="ttlm_backgroundColor">#2B3339</item>
<item name="ttlm_strokeWeight">1dp</item>
<item name="ttlm_cornerRadius">2dp</item>
<item name="ttlm_arrowRatio">1</item>
<item name="ttlm_elevation">4dp</item>
<item name="ttlm_textStyle">@style/ToolTipTextStyleCustom</item>
</style>
<style name="ToolTipTextStyleCustom" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/white</item>
<item name="android:textColorHighlight">@color/white</item>
<item name="android:textColorHint">@color/white</item>
<item name="android:textColorLink">@color/white</item>
<item name="android:textSize">24sp</item>
</style>
You will receive an error if you do not have these:
<item name="android:textColorHighlight">@color/white</item>
<item name="android:textColorHint">@color/white</item>
<item name="android:textColorLink">@color/white</item>
since appcompat does not handle those.
Have fun like I had while debugging this.