简体   繁体   中英

Android textview shadow doesn't work using style.xml

I have a textview that I set its style to a style I made with a shadow. I declared the settings I want in the style.xml InfoTextstyle and set the textview style to the style but it doesn't work.

This is the style.xml :

<style name="InfoTextStyle" parent="AppBaseTheme">
        <item name="android:textColor">#fff</item> <- works
        <item name="android:textSize">18sp</item> <- works
        <item name="android:shadowColor">#ff0000</item> <- don't works*
        <item name="android:shadowRadius">5.0</item> <- *
        <item name="android:shadowDx">2.0</item> <- *
        <item name="android:shadowDy">2.0</item> <- *                  
</style>

& this is the activity_main.xml :

<TextView
     android:id="@+id/brightness"
     style="@style/InfoTextStyle"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerHorizontal="true"
     android:layout_gravity="center_horizontal"
     android:layout_marginTop="15dp"
     android:text="@string/brightness"
     android:textAppearance="?android:attr/textAppearanceMedium" />

I'm new to android, so I'm not sure what's the problem.

A few things to try:

  1. Look on a real device, not in Eclipse "Graphical layout" which does not support text shadow.
  2. Decrease the shadow radius to 1. The larger the radius, the more blurred the shadow is.
  3. Check if the style file you wrote in in the main "values" directory or under values-?dpi. Maybe your device dpi does not target your style file

Use this XML code in your TextView declaration instead of using Styles

<TextView  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="A light blue shadow."  
    android:shadowColor="#00ccff"  
    android:shadowRadius="1.5"  
    android:shadowDx="1"  
    android:shadowDy="1"  
    /> 

-android:shadowColor Shadow color in the same format as textColor.

-android:shadowRadius Radius of the shadow specified as a floating point number.

-android:shadowDx The shadow's horizontal offset specified as a floating point number.

-android:shadowDy The shadow's vertical offset specified as a floating point number.

Also use this link to pick your Color code http://www.w3schools.com/tags/ref_colorpicker.asp

EDIT:

TextView textv = (TextView) findViewById(R.id.textview1);
textv.setShadowLayer(1, 0, 0, Color.BLACK);

Also take a look at this link for Style way https://stackoverflow.com/a/2487340/1364896

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM