android setEnabled but unchange text - java

I have some edit text fields which I would like to make un-editable at certain times. I have used the setEnabled method but that also grays out the text. Is there a way to toggle whether the field can be edited but not change the appearance of the text? It has been a little while since I last messed with Android but I think I used to be able to use setEditable which did exactly what I am looking for.
I have tried to use the android:focusable="false" but I am still able to edit the field, unless that is only the behavior of the emulator I don't think that will work.

You can disable input for an EditText without any visible indication by setting it's input type to InputType.TYPE_NULL. An example would look like:
import android.text.InputType;
. . .
myEditText..setInputType(InputType.TYPE_NULL);
Note that this behavior doesn't exactly jive with what the reference docs seem to be saying and that there doesn't appear to be an XML equivalent.

Related

How to pinch zoom an edittext in android?

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.

How disable the spinner in PrinterJob.pringDialog()?

I get the dialog for changing the properties of the print job by invoking the PrinterJob's printDialog() method without any parameter. There is a field where the user can change the the number of copies to be printed on the right-bottom of this dialog.
And now I want to disable this field (the spinner). That is only one copy to be printed and the user can't change it.
Are there any ideas for it
I don't think there is any way (or i am not aware of) to modify the native or the cross-platform Java print dialogs (last one might help you a bit). What you could do is maybe display your own dialog (without a spinner field) and under-the-hood do whatever you want (like PrinterJob.setCopies(1)).
More info i found here.
Also, have a look at the Java tutorial on PrinterJobs.

java multiline button - disable color-issue

i have the following problem:
i want a JButton with a line break. i am using the html method to get it done.
<hmlt>Bla<br>Bla</html>
the problem appears if i disable the button. it works fine except on the "html-styled" button. the color from the button stays the same.
on an other button i am just using &#8592+;(without the "+") and it works fine, the arrow gets grayed out if i disable him.
so i searched some time for the unicode or html number for the line break, but it didnĀ“t work(for example &#10+;)
so can anybody give me an advice? i know it could be done in java, but i prefer the html way, cause it is faster to implement :)
See How to Use HTML in Swing Components: ButtonHtmlDemo:
..Note also that when a button is disabled, its HTML text unfortunately remains black, instead of becoming gray. (Refer to bug #4783068 to see if this situation changes.)
I don't think components with HTML text will be affected by the modified text style that disabling them usually causes.
You could override the button's getText() method to return a different HTML including styling for the text depending on whether the button is disabled or not, but if you want to get it just right it would probably be easier to extend the UI to allow multiple lines without relying on HTML.

Java StyledDocument: How can I ensure that what the user types never appears already styled?

The user types some text. When they press a button, what they have typed is split up and colour coded:
colors.setCharacterAttributes(characters, tokens[x].length(), formatBlue, true);
Using a set of rules.
When they make an edit between the position as defined by characters and the position characters + tokens[x].length() it comes up in my formatBlue style.
However, I would like it to be in black until the user next presses the 'colour code' button I have.
In short: the desired effect is that everything that is typed should always in black, until it has been phrased and coloured differently by the program.
So far, the best solution I have is to detect when the caret changes position, and then do:
setLogicalStyle(textArea.getCaretPosition(), formatBlack)
Any better suggestions would be appreciated.
the desired effect is that everything that is typed should always in black
You could try using a DocumentFilter. If the text about to be inserted does not contain an attribute then you assign the default black attribute.
Read the section from the Swing tutorial on Implementing a Document Filter for more information.
You can get EditorKit from your JEditorPane. It's StyledEditorKit instance. So you can get InputAtributes from the kit and remove all the attributes. Thus all the typing will use the empty AttributeSet.

Ability to view text in each class

Recently, I program for the Android platform. I have a question about the text.
Is there any way to display the text without using the XML?
I also want the text to be able to show in each class.
If you're asking if you can replace the text of anything programatically, yes you can. Usually, you have a setText method you can use for that. I'd advise you to read the tutorial and the javadoc to know more about this.

Categories

Resources