Trying to set color to my text in android -


i trying set color text in android. every time launch application shuts down. here have in color.xml file:

<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <color name="background_color">#006400</color> <color name="app_text_color">#ffe4c4</color> 

here have in mainactivity class:

int textcolor = getresources().getcolor(r.color.app_text_color);          textview hellotext = (textview)findviewbyid(r.string.hello_world);          hellotext.settextcolor(textcolor); 

here layout file:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <textview         android:id="@+id/hello_world"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/hello_world"          />    </relativelayout> 

log car:

04-17 21:00:39.290: e/androidruntime(9986):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:1670) 

instead of

textview hellotext = (textview)findviewbyid(r.string.hello_world); 

you have use id in findviewbyid, like

textview hellotext = (textview)findviewbyid(r.id.your_textview_id); 

here your_textview_id id of textview in layout xml..

<textview     android:id="@+id/your_textview_id"      .............       ......... 

i tried , worked me:

textview hellotext = (textview)findviewbyid(r.id.hello_world);  hellotext.settextcolor(getresources().getcolor(r.color.app_text_color)); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -