Seekbar progress isn't destroyed when activity is rotated - android

I place a discrete seekbar in my layout. When I run my code in the emulator and rotate the screen, the activity gets destroyed, but for some reason the seekbar progress stays the same. Why does this happen, shouldn't the progress be reset?

Built-in Android View widgets such as TextView, EditText and SeekBar have their state automatically saved and restored when the device configuration changes (in your case, when you rotate the screen), provided they have an id.
That's why your SeekBar's progress is not reset when the screen is rotated.
If you'd like to disable this behavior, you can add android:saveEnabled="false" to your view definition in XML.

Related

Change android seekbar value without clicking direclty on the seekbar thumb

I have an android seekbar that appears on the screen when a user touches a button.
How can I start tracking user touch to move the seekbar immediately after it appears?
To be more clear, essentially I want the user to be able to move the seekbar thumb/progress without clicking directly on it.
Seekbar extends ProgressBar, so just call setProgress on your SeekBar to update it.
See this for reference.

Animated Android View with EditText

For the app I'm working on, the signon screen (the main activity) has some animations. Several of the signon related controls (the EditText, an application banner image, the signon button, locked out link, etc) are wrapped into a LinearLayout that starts out centered in parent within a full screen RelativeLayout. When the user taps into the EditText, the animation fades out the banner image as the logon form translates to the top of the screen. When the user dismisses the keyboard the banner image fades in as the form slides back down to the center of the screen.
The two issues are as follows (the first one is the most important since I don't have a workaround for it right now):
When the user is typing into the EditText after it's been animated to the top (it isn't actually animated to the top, the containing LinearLayout is) then you almost never see any text that is typed. It's random... sometimes the hint stays there and sometimes you might see a letter or two. When the keyboard is dismissed and the animation moves everything back to the start, the text is visible. Why?!
When the signon screen is put into the background and then resumed, Android appears to show some cached version of the screen where the controls are in their "focused" state but none of them work. Tapping on the screen where the controls would normally be (in the center) reveals the controls and starts the animation to move them to the top. This happens even if when the screen goes into the background, it's in it's regular state. I "fixed" this by setting a flag when the activity is paused and then checking if the flag is set in resume... if it is then I recreate the activity (by launching a new intent, not by calling recreate since I have to support an older API). It would be awesome if it just didn't show the cached version without me having to jump through these hoops.

Android WebView does not render before I lock/unlock the screen

So I have an activity with a WebView with the visibility set to Gone on startup. After a button click, I load the web view with content, set it to Visible and call invalidate() in that order. Yet, it does not render or layout before I turn off the screen (lock the phone) and then back on again. Why not?
It has set height to wrap_content. I'm running Android 4.1 on a HTC one.

Android: how to disable FEATURE_NO_TITLE

I want my Android application to behave like below.
1) Portrait mode: With title bar
2) Landscape mode: Without title bar (because of height limitation)
I know I can realize 1) using requestWindowFeature(Window.FEATURE_NO_TITLE), but
how can I dynamically change from 1) to 2) when I rotate my phone?
When the phone is rotated, your activity is shut down and recreated. Inside onCreate, you can grab an instance of Display (using getWindowManager().getDefaultDisplay()) and query its width, height, and/or rotation to decide if you want a title feature, all before setting the content view.
This answer suggests you can't change the feature during the lifecycle of the activity (as happens when the orientation changes), so they recommend implementing your own title (jump to the "::Edit::" part):
Hiding Title in a Fullscreen mode?
::Edit::
Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called.
One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track
Since when you change orientation, your app goes through a set of lifecycle changes, you have an opportunity in onCreate to show or hide your title.
http://stuffthathappens.com/blog/2008/11/26/android-lifecycle-triggers-part-2/
Or you specify a different layout altogether for landscape mode:
http://developer.android.com/resources/tutorials/hello-world.html
Landscape layout
When you want a different design for landscape, put your layout XML file inside /res/layout-land. Android will automatically look here when the layout changes. Without this special landscape layout defined, Android will stretch the default layout.

'Unset' Button background

I'm changing the background drawable for my buttons when they're clicked (as they trigger functions such as play/record). While playing/recording, the button glows (a different 9-patch is set as the background) and turns into a stop button. My problem is that currently I'm using:
b.setBackgroundResource(R.drawable.btn_default_normal);
to set the background back again afterwards. This works, but the normal behaviour when I use setEnabled(false) is lost. After a button has been used, and reset to normal, it retains the normal background (rather than the dimmed one) when disabled. The text still changes colour though. Is there a way of 'resetting' the background of the button to default, so that it retains its normal behaviour?
Ok, I got the answer from this blog post in the end. What you have to do is create an xml document with all the different button states, and assign that rather than just an image to the background.

Categories

Resources