Setting the theme in an app

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

Setting the theme in an app

Postby gsmith53 » Sat Dec 01, 2007 6:17 am

I wrote a simple little Activity to test some of the API features. All it has is a radio button group that has 2 choices. These are the 2 supplied themes. It also has an EditText to accept a URL to browse to with a go button.

Two things are happening that I don't seem to understand.

1) When I capture that the user has clicked on the radio button group to change the theme, I call setTheme(new theme) in my OnClickListener, but nothing happens. If I save the change to the theme to a preferences file, and then use the stored theme when I start up the Activity, it works fine. So, the question is: At what point in the life cycle of an Activity should you be able to change the theme? It seems that only during onCreate() works right now.

2) The "Go" button to launch the browser starts out disabled, and when the user enters something in the EditText field, my OnKey listener attempts to enable the "Go" button if the URL length is greater than 1. But the button facade doesn't seem to change until some other activity happens on the view. Shouldn't I be able to change the enabled status of a control at any point based upon my business logic?
gsmith53
Freshman
Freshman
 
Posts: 9
Joined: Sat Dec 01, 2007 5:40 am
Location: Dallas, TX

Top

Postby plusminus » Sun Dec 02, 2007 2:37 am

Hello gsmith,

sorry that my answer is a bit late, but its weekend and I even got a real life ;)

1.) Yes, you can also set the theme programmatically, if needed. When doing so, be sure to set the theme before creating any views so that the correct theme is used for all of your user-interface elements.
That seems pretty logical to me. So you probably have to say "The Theme will be applied with the next start..." Almost every program (FireFox, Thunderbird, ...) does it the same way (restart needed).

2.) Did you try an invalidate(); after altering the enabled-State :?:
What did you mean with:
gsmith53 wrote:...
But the button facade doesn't seem to change until some other activity happens on the view.

You mean a real Activity or just that anything happens. (In the second case the invalidate(); tip could help.)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby gsmith53 » Mon Dec 03, 2007 4:05 am

plusminus wrote:sorry that my answer is a bit late, but its weekend and I even got a real life ;)

1.) Yes, you can also set the theme programmatically, if needed. When doing so, be sure to set the theme before creating any views so that the correct theme is used for all of your user-interface elements.
That seems pretty logical to me. So you probably have to say "The Theme will be applied with the next start..." Almost every program (FireFox, Thunderbird, ...) does it the same way (restart needed).

2.) Did you try an invalidate(); after altering the enabled-State :?:
What did you mean with:

You mean a real Activity or just that anything happens. (In the second case the invalidate(); tip could help.)"

I understand completely. :D I only have the weekend to play with Android... :D

I understand what you are saying about the theme, but as I generally write J2EE web applications, themes generally take effect immediately, no restart required. If it's a user choice to change the theme, they are not likely going to like having to restart to have it take effect. I understand the limitation now though. So, thank you for the answer.

Thanks for the invalidate() also. I'll try that as soon as I get a chance to get back to playing... :)
gsmith53
Freshman
Freshman
 
Posts: 9
Joined: Sat Dec 01, 2007 5:40 am
Location: Dallas, TX

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 22 guests