I've tried adding gradient effect to TextView
. But it generates a NPE
(I felt the id
to was the culprit, but it wasn't so).
My Activity
:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
TextView textView = (TextView)findViewById(R.id.label);
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.GREEN,Color.BLUE},
new float[]{0, 1}, TileMode.CLAMP);
textView.getPaint().setShader(textShader);
// storing string resources into Array
String[] menulist = getResources().getStringArray(R.array.menulist);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, menulist));
}
My XML
:
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
I feel I'm missing something obvious.
If there's any other way to attain a list with a gradient color effect, feel free to suggest.
NPE
at line :label.getPaint().setShader(shader);
– Elapse