package com.loaderman.customviewdemo; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView)findViewById(R.id.tv); tv.setShadowLayer(2,5,5, Color.RED); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:background="@android:color/white" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:text="动态代码阴影效果" android:layout_gravity="center" android:gravity="center" android:textSize="18sp" android:layout_height="wrap_content" /> <TextView android:layout_width="match_parent" android:text="XML实现阴影效果" android:layout_gravity="center" android:gravity="center" android:textSize="18sp" android:shadowColor="@color/colorPrimary" android:shadowDx="5" android:shadowDy="5" android:shadowRadius="5" android:layout_height="wrap_content" /> </LinearLayout>
效果: