I have an Activity that consists only of a huge EditText, full screen.
To match with my app's colours, i changed the background color of the EditText. But although it occupies the whole screen, it only changes the first line. Everytime i press enter i go to a new line and that line gets the background i want.
What propertie can i set in order to do this? I just can't see it!
I would wrap the EditText with a View and set the background color on the View.
In order to change the background of those Views that come with a background already, its better to provide your own image, and then use patch9 for proper resizing
I hope that helps
#everyone:
While searching for a solution for this same kind of problem i found this page. While reading the solutions i thought to myself: "There must be a better way to do this, instead of making your own styles and widgetborders, etcetera, etcetera, ....
Therefore, i present to you: the 1 LINE OF CODE SOLUTION!!! No trolling.
<your-widget-component-that-has-a-background-color>.getBackground().setColorFilter(Color.<your-desired-color>, PorterDuff.Mode.MULTIPLY);).
It works like this:
"getBackground()" fetches the background from the component
"setColorFilter" will call a filtering on the background image itself
"Color." determines what color you want to pass onto the filter
"PorterDuff.Mode." sets the kind of manipulation you would like to do with the given color and the fetched background image. People with knowledge of image editing software (GIMP, Photoshop, ...) might recognise these modes. Basically, each mode has a certain effect on how the color is applied to the background image. to simply "override" the color of the image, while preservind it's gradients, borders and such, use "MULTIPLY"
I haven't profoundly read the PorterDuff class documentation, but honestly, ain't it a powerful bit of code?
With kind regards,
How to set the background color of an EditText widget:
editText.setBackgroundColor(Color.RED);
Related
Please suggest a way to zoom all the contents of the edittext when a pinch gesture is detected. Want to zoom like typical text editor apps like KingSoft and quickoffice.
It's going to be nasty, but you can subclass EditText.
In your subclass, override onTouch and pass its values to a ScaleGestureDetector. Store the detected scale as a member variable.
Override onDraw, and call canvas.scale() with your scale value prior to calling through to super.onDraw.
This is likely to wreak havoc with the caret and edit controls.
I wrote a simple library to do just that, back when I need the functionality in an app. You can find it on GitHub
To add tad's answer, you probably can use children of MetricAffectingSpan or CharacterStyle:
http://developer.android.com/reference/android/text/style/MetricAffectingSpan.html
You will have to handle copy/paste (with spans!), and it will be tedious.
Note that you can derive your own spans from the existing classes, but I cannot say what will happen with them when you copy & paste the text into another application.
OTOH, if you decide from the very beginning that your text is just plain text and there is only one span used for zooming, it may be not so tedious.
If I make button relatively small, it's caption turns to ellipsis.
How to turn off this feature?
Don't let the button go below it's preferred size, then it will never need to elide the text of the button label:
button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);
I want to make very small button
You can use any of the below either separately or in combination:
Apply CSS to use a very small font in the button.
Make the label text for the button very short.
Use brian's answer which proposes explicitly setting the ellipse string to empty.
Use a small graphic icon instead of text.
You can use setMinSize as documented above in all cases (if you wish the button not to go below a preferred size truncating or eliding content).
In all cases, if you wish, you can also apply CSS to minimize the padding between the label and button the border.
From your previous comment (I want to use simple captions like "<" and ">"), I think option 2 (Make the label text for the button very short) is what you want.
You may also be interested in Joel's Designing for People Who Have Better Things To Do With Their Lives which would indicate, usability-wise that very small buttons are usually a pretty bad idea.
in your label/button you can use the textOverrun property to turn off ellipsis.
textOverrun.set(OverrunStyle.CLIP);
this is probably a bit late for you, so i am putting it here for lone wanderers digging up this question.
It puts ... because there's no room for the text. You can use bigger buttons or a smaller font but if you really want the dots gone use button.setEllipsisString(""); , but then you just get truncated text.
I want to be able to add a text-messaging balloon every time the user revives data from a HttpGet, I want it so that it looks nearly identical to the default Android text messaging UI. I'm fine with all the code, I just need a way to create the UI and create another text balloon every time data comes back from a HttpGet request.
Thanks ever so much, for the answering this questions and I'm sure there's an easy way to do it, yet I've found no way by using the 'ole Google.
I am doing something similar for my app am doing the following to achieve it:
You will need a 9-Patch-Image (a stretchable PNG, see here) that represents the bubble. You want to make the part stretchable that does not include the corners of the bubble. You can create the bubbles using an image editor of your choice (I'd recommend a vector graphics editor like Inkscape). Then use the 9-Patch editor included in the Android Developer Tools to transform the PNG image into a 9-Patch PNG.
Create a custom layout file for one bubble. Create a textview inside it, and add your bubble as a background resource. (android:background)
Use an arraylist with a custom adapter to inflate and fill your items.
So far, this will give you identical bubbles as background for all messages.
If you want to get fancy, you can create different bubbles for participants, and use the setBackgroundResource method in your Adapter to set the correct background.
Further, if you wish to align them left or right, like in the message app, you will need to add spacers to the left and right of your TextView in the layout file. I used FrameLayouts with a fixed width. Make sure to set their visibility to GONE.
As with swapping the different bubble colors, just set the visibility of the left/right spacer.
I'm fairly confident that I have done my research before coming to you for help, but it's possible I have overlooked something.
I'm writing a java UI using the Nimbus l-a-f. I wish to change the background colour of a JSpinner on state-change, ie, when either the up or down button is pressed the background colour of the textfield within the jspinner changes colour to signify that the value has been altered.
I am aware this is possible using OTHER lookandfeels but not as easy with Nimbus, eg:
((JSpinner.NumberEditor)jSpinner1.getEditor()).getTextField().setBackground(color.yellow);
I have also looked into actually changing the colour theme of the UI manager, but I only want to change the colour when an action occurs, not just overall by default.
here or here
Is this at all possible and where do I start?
Failing this, I was hoping to just change a button's colour:
jButton.setBackground(Color.yellow);
This is easy enough but since the default colour is a painted gradient, how do I change it back to that?
Really hope someone out there knows or can help.
Much appreciated in advance!
Yes, it is possible. See this example (i.e. SpinnerDemo4) from The Java Tutorials for more detail. And yes, I did set the LaF to Nimbus when testing the code therein.
I have the following code:
View view = new View(this);
view.setBackgroundDrawable(...);
...
And here I want to remove that background.
Just turn it back as it was before.
I tried these and failed:
view.setBackgroundDrawable(null);
view.setBackgroundColor(0xFF000000);
view.setBackgroundColor(0x00000000);
Any more ideas?
view.setBackgroundDrawable(null); should work.
You may try one of these:
v.setBackgroundColor(Color.WHITE);
//or
v.setBackgroundColor(Color.parseColor("#ff0000")); //whatever color
Make sure the view you're applying the background to is the correct instance.
That's because view.setBackgroundColor(int) expects a color resource not an "actual" integer value. Try declaring it in your colors.xml, see this. However, I'm not quite sure what you mean by "removing" the background. If you want it to have the original value, then I suggest you store the original drawable (using getBackground()) somewhere. Otherwise you will most likely lose formatting, since most default backgrounds in Android are Drawable resources (selectors), not simple colors.