How to change button or textView text color or style

Put your problem here if it does not fit any of the other categories.

How to change button or textView text color or style

Postby blockhead » Wed Apr 02, 2008 10:55 am

Hello,
I want to change botton or textView text color using java code ,I use the code below,but it don't work.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void SetNavigateButtonDisable(Button v)
  2.  
  3.     {
  4.  
  5.         v.setOnClickListener(null);
  6.  
  7.         //v.setBackground(R.drawable.navigation_btn_disable);
  8.  
  9.         v.setTextColor(R.color.navigation_btn_disable);
  10.  
  11.         v.invalidate();
  12.  
  13.     }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


I don't know why.Who can tell me,TKS.
blockhead
Freshman
Freshman
 
Posts: 2
Joined: Tue Jan 08, 2008 6:57 am

Top

Postby blockhead » Thu Apr 03, 2008 1:58 am

anyone know?
blockhead
Freshman
Freshman
 
Posts: 2
Joined: Tue Jan 08, 2008 6:57 am

Postby Jesmiatka » Thu Apr 03, 2008 8:32 am

Hi,

You are using a resource for what I think should be a color.
Normally if a function needs a resource, the javadoc will say the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  setTextColor(int resId)
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But! setTextColor ask for a int color which means we would use the following approach:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 loginbt = (Button) this.findViewById(R.id.login_bt_login);
  2.  
  3.                 loginbt.setTextColor(Color.RED);
  4.  
  5.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Hope this will help
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby Jesmiatka » Thu Apr 03, 2008 9:00 am

by the way if you want to use the Color that is in that R file do the following

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 v.setTextColor(getResources().getColor(R.color.navigation_btn_disable));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 22 guests