sephiroth74 / android-target-tooltip

Create Toast like tooltips, but targets can be specified, plus custom properties and features
MIT License
1.49k stars 278 forks source link

simple way to set the text color? #11

Open splitbrain opened 9 years ago

splitbrain commented 9 years ago

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?

Desno365 commented 9 years ago

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).

kevinmost commented 8 years ago

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));
sytolk commented 8 years ago

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

iam1492 commented 8 years ago

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>
rohan20 commented 5 years ago

@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.

Desno365 commented 5 years ago

@rohan20 I'm sorry but I commented on here 4 years ago. I don't even remember for what I used this library.

jmsalcido commented 4 years ago

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.