Pregunta

I want the Marquee effect on EVERY textview in my app...so I thought I put it in a style:

<style name="MyTextViewStyle" parent="@android:style/Widget.TextView">
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
    <item name="android:fontFamily">sans-serif-thin</item>
    <item name="android:textSize">25sp</item>
    <item name="android:ellipsize">marquee</item>
    <item name="android:singleLine">true</item>
    <item name="android:maxLines">1</item>
</style>

and set it in the app theme:

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/MyTextViewStyle</item>
</style>

this doe not work :(

Tried it directly on the TextView:

<TextView
    android:ellipsize="marquee"
    android:singleLine="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:maxLines="1"
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="-5dp"
    android:fontFamily="sans-serif"
    android:textAllCaps="true" />

This does work...

With the following condition: the style may NOT have the 'focusable' and 'focusableInTouchMode' options. But without these uptions in the TextView example above, it will not scroll...

so I need these attributes, but am unable to get them to work via styles...anyone have an answer?

¿Fue útil?

Solución

If focusable and focusableInTouchMode not working in Style then remove from Style.xml and add in every TextView

<style name="MyTextViewStyle" parent="@android:style/Widget.TextView">
    <item name="android:fontFamily">sans-serif-thin</item>
    <item name="android:textSize">25sp</item>
    <item name="android:ellipsize">marquee</item>
    <item name="android:singleLine">true</item>
    <item name="android:maxLines">1</item>
</style>



<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/MyTextViewStyle</item>
</style>

In Your layout.xml file.

<TextView
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="-5dp"
    android:textAllCaps="true" />

Note : this will work if there is only one TextView in layout..

If you have many TextView as marquee in single layout then look at this example, Android-MarqueeView.

Otros consejos

I'm guessing that android:ellipsize is not a text style element, so it is not inherited with android:textViewStyle.

Just add your MyTextViewStyle as a style to a TextView to check my guess. If this is the problem, you have to add the android:ellipsize attribute individually or in a style.

try this :

<TextView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textAllCaps="true" />

and marquee effect will work only if text length is bigger than scree width.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top