Dynamically change titlebar height in android - android

I'm using a custom titlebar created for my own use in the app i'm making, containing the title and some buttons. However occasionally I get titles that are slightly too long for the titlebar, where the titles are out of my control.
Currently setting the titlebar's height through "android:windowTitleSize="70dp"" in the titlebar's theme, but is there a way to dynamically change it if I can detect that the incoming title is too long and falls over into two lines?

I didn't find a solution for this either.. but you could try android:ellipsize="end".
This way if the text will flow out of the TextView's bounds, the text will be cut of at the end and "..." will be added to the text.
Here is also the documentation.

Related

change Color of one word in a preference summary

Does anyone know how to do this? For me, I would try the usual Html or Spannable that everyone recommends on SOF.However,nothing changes - the preference color stays light gray (I am on android 4.2), unless I try coloring the ENTIRE message - then it works. But I just want a single word in the middle of the sentence to be colored - not the whole thing. The rest should be gray (or whatever the default is on my android).
OK, the issue was that I was supposed to wrap the entire text in Html.fromHtml method. Not just the portion with text I was coloring.

Wrap text in button gracefully at whitespace

I have an android application in which a user can create what is basically a macro and label that macro with some text. I then create a button for them with their descriptive text. The button is a custom view extending Button. In the constructor I set the layout as follows:
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
These buttons are then placed within a GridView. Functionally, it's working as intended but I'm running into a layout issue.
If the text is too long, it will break and wrap to the next line, thus increasing the height of the button while maintaining a constant width. The problem is in how the text wraps, it will break in the middle of a word, instead of gracefully wrapping at whitespace. For instance the test "Perform an Action" will render as
Perform an Ac
tion
Ideally, I'd like to wrap gracefully at whitespace instead of breaking words across lines. I suppose I could do this by checking the length of the text and the font against the width of the button and then doing some fancy insertion of newlines myself, but that gives me traumatic flashbacks to making win32 UIs. Is there a better way?
you can add this attribute to your Button's XML that will magically put the whole text in one line:
android:singleLine="true"
or you can verify the text before you insert it to the button and check the number of words.. if it is too long like more than 25 characters then break it on the second or third whitespace then set it to the button.
hope I got your question right.
AFAIK there's no simple way to do precisely what you want. You can get a decent look using android:singleLine="true" and android:ellipsize="marquee". Also, since you have already implemented your own Button class, take a peek at this question
I had a button which said "Off" and had a drawable to the left, but it was wrapping to two lines. i.e.
Image O
ff
The solution was that I removed the drawablePadding style. i.e.
<item name="android:drawablePadding">5dp</item>

How to change the text color of the error popup for an EditText?

On ICS, when using a theme based upon android:Theme.Light the text in the error popup when using setError(...) is white, as is the background.
I can fix this issue by adding <item name="android:textColorPrimaryInverse">#ff000000</item> to my theme. While this helps I'm a bit worried that by doing that change some other text, that uses textColorPrimaryInverse will turn from white to black and perhaps not be visible. I would rather just change that attribute for the EditText that displays the popup in question or for just that activity.
Clarification
I would like to change a property, preferably the text color, of the popup that displays the error message when the user enters something wrong into an EditText.
You can do it like this:
editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));
In code use http://developer.android.com/reference/android/view/View.html#setBackgroundResource(int) or http://developer.android.com/reference/android/view/View.html#setBackgroundColor(int). They belong to View, but EditText inherits them. The second methiod is easier, the first is more consistant.
Edit: Oh, it is a more hard question.
Maybe, using EditText.setError(CharSequence error, Drawable icon) you can put error text on the icon? You can set setBounds(Rect) for the icon, so, it could be enough big. The icon can be the color you need.
But I use onKey,beforeTextChanged, onTextChanged and show my own error message as a Toast. For the toast you can use an usual View.

iphone-style text edit on android

I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.

How to "truncate" a text inside textview in android according to the orientation?

I created a simple java function to truncate a string to be displayed in my list view. I am displaying a news title and below this a news summary. I would like to have the same behavior as the image below. Currently, i am truncating the news title with 45 chars and then appending "..." at the end of it. However, when I change the orientation to landscape, the title could appear without being truncated. I dont think the app below truncates the news title, but it keeps the title in a single line and automatically "truncates".
How can I achieve this behavior in my app?
I don't think you need to truncate title manually. Android TextView component has ellipsize attribute that will do that for you. That also should adopt to any screen orientation.

Categories

Resources