As of recently (probably as a new SDK feature), when I try to pull text from a Textview, I first get the method getFreezesText(), instead of getText().
I looked at the definition of this method and it says
**android:freezesText**
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol freezesText.
Related Methods
setFreezesText(boolean)
This tells nothing to me.
When we are supposed to use these methods (if ever at all)? Are they new or I've just noticed them?
If you want to force your TextView (or EditText etc. for that matter) to save its state you must add freezesText attribute:
<TextView
...
android:freezesText="true" />
From documentation on freezesText :
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider
The attribute and method have existed since API 1, so I'll say you just noticed it.
android:freezesText="true" will freeze your last completed text.
What is the last completed Text?
Suppose you are showing a textView which is changing after every 2 seconds everything is okay until you rotate the screen and if you rotate the screen the text inside textView will not be visible, here freezesText comes, it will freeze the last showed text (last completed Text).
Related
I am wondering if there is a way to assert on the style of a WebView element's contents in Espresso. I am aware of the ability to get the text of an element, however, I would like to do more testing. I haven't been able to find clear documentation on how to do things like getting the background-color or text-color of a button or the text-size using the onWebView.withElement logic. Is this even possible?
Consider this example:
Web.onWebView(withId(R.id.my_btn_id))
.withElement(findElement(Locator.ID,"_the_id_of_a_button"))
.check(webMatches({how to reference button text color}, "#0102333"));
Web.onWebView(withId(R.id.my_btn_id))
.withElement(findElement(Locator.ID,"_the_id_of_a_button"))
.check(webMatches({how to reference background color}, "#0302223"));
Web.onWebView(withId(R.id.my_btn_id))
.withElement(findElement(Locator.ID,"_the_id_of_a_button"))
.check(webMatches({how to reference text size}, "12px"));
Even getting the style value would help.
Note, I am aware of how to obtain these via evaluateJavascript. This is purely an Espresso question.
I just want a simple non-editable text label but there doesn't seem to be a widget explicitly for it. The closest thing seems to be a android.widget.TextView. But the documentation says a "TextView is a complete text editor". That seems like overkill for a simple label. I don't want to bloat my application. Is there a more appropriate widget?
Or am I approaching this the wrong way? For example, let's say I'm building a settings screen, is there a layout I should choose which gives me labels for the properties so I don't have to specify widgets for the labels?
Is there a more appropriate widget?
No.
I don't want to bloat my application.
You won't, unless you put a ton of text in it. While TextView has a lot of code, your process will already have access to that code, whether you use TextView or not. The only "bloat" would come from the actual heap space used by the TextView object itself (and objects that it holds).
For example, let's say I'm building a settings screen, is there a layout I should choose which gives me labels for the properties so I don't have to specify widgets for the labels?
Typically, we would use a PreferenceFragment, backed by a preference XML resource, instead of having any layout or widgets.
But, if you wanted to roll your own for some reason, use TextView for the labels.
I have a timepicker showing the choice, but also shows the previous option above, and the next option below. I wish they would show these options are not, and it would show arrows such as in the image attached: http://www.subirimagenes.net/i/140728103732203512.png.
I have searched but have not found any solution.
From android/widget/NumberPicker.java:
If the current theme is derived from android.R.style#Theme the
widget presents the current value as an editable input field with an
increment button above and a decrement button below.
If the current theme is derived from android.R.style#Theme_Holo or
android.R.style#Theme_Holo_Light the widget presents the current value
as an editable input field with a lesser value above and a greater
value below.
According to this, before Holo the widget looked exactly how you wanted it. So try adding android:style="#android:style/Theme.Black" inside the <TimePicker /> in your layout xml file.
Is there any shortcut for editing properties of a widget in Android Layout editor in ADT?
I need to change gravity of TextView lots of times, but every time I have to use mouse...
You could do a search and replace on a particular string in the layout.
Highlight only the TextViews you want the search to happen in
Search > Search
Enter the string to be replaced and press the "Replace" button or "Replace
All" button.
If you post the exact xml listing of your layout, I can be more exact in which string needs to be replaced. If that solution doesn't work for your particular case, to save some time, I suppose you might also be able to create a particular custom Eclipse template for your TextView.
A third option would be to use inheritance and create a customTextView with the gravity already set a certain way.
And a fourth option still would be to set the properties of your TextViews programmatically after the fact using both XML and Java (instead of only using XML).
I created a simple app that has nothing except an EditText element. When I run the app, I type text into the element and then press Ctrl-F11 to change the emulator's orientation. I've added logging information to make sure that the activity gets destroyed and re-created when I change orientation. I haven't added any code to save the text in the EditText element and yet, after the change of orientation, the text that I typed stays in the EditText element. What mechanism in Android is saving and then restoring the element's text (is it savedInstanceState) and how can I see for myself the details of this saving operation?
onSaveInstanceState()/onRestoreInstanceState() along with unique widget IDs. Some links that utilize:
Saving Android Activity state using Save Instance State
http://groups.google.com/group/android-developers/browse_thread/thread/5d7fd8da11c8e971