I am new to Android. I have a paragraph in string which looks like below
String my_paragraph ="Software is a set of instructions, data or programs used to operate computers and execute specific tasks. It is the opposite of hardware, which describes the physical aspects of a computer. Software is a generic term used to refer to applications, scripts and programs that run on a device."
textView.setText(my_paragraph);
I want to display it in the Text View like this below image:
But what I got is I added below
I want the first line in text view(paragraph) should starts in the middle. I don't want to add leading spaces in string. I don't know how to achieve this. Please help me with some solutions.
Android has libraries that can do this for you. I found an old post with a great how to use the SpannableString and LeadingMarginSpan libraries.
The question can be found at: What is Leading Margin in Android?
try to add \t or \u0009 (tabulator character) at the begining of String - this is a symbol of default indetation for paragraphs
textView.setText("\u0009" + my_paragraph);
Related
I am porting my Android app to iOS and I am using Codename One for that.
In my app an EditText can contain icons mixed with text. It is accomplished with instructions like these:
MyImageSpan iconSpan=new MyImageSpan(activity, R.drawable.icon);
editText.getText().insert(caretPosition,CHAR);
editText.getText().setSpan(iconSpan,caretPosition,caretPosition+1,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
then in other parts, spans have to be detected, if present, and it is performed like this:
Editable editable = editText.getText();
for (int i = 0; i < editable.length(); i = next) {
// find the next span transition
next = editable.nextSpanTransition(i, editable.length(), MyImageSpan.class);
// get all spans in this range
MImageSpan[] tempSpans = editable.getSpans(i, next, MyImageSpan.class);
...
...
//In my app that becomes really complex
...
...
...
...
}
I tried to use this online tool:
http://fontello.com/
to manage icons like font glyphs, as it seems to be adviced by Codename One documentation.
In fact I do not understand if it is possible to have spans with different fonts in an TextField in Codename One, and I do not know if I could find and manage them inside the TextField.
But the most important thing is that the online tool to create fonts out of svg files did not work for me because some icons are reverted, others are broken or confused, others are tiny, depending on the saving format (eventually I saved in pure SVG format to avoid issues but it's the same).
What I am asking is how to handle the spans in the TextField in Codename One.
It has not to be the same "way" but the result has to be the same.
This won't work. Rich text edit is something that's just too different between platforms and isn't universally available. Since the edit component is implemented using native widgets it's very hard to consistently abstract something like this and effectively impossible.
However, web tools solved that problem already and include some cross platform rich edit tools that work. You can just use one of those tools and embed a BrowserComponent in your app. Then perform the rich editing within the browser component.
Back in the day we did it with CK editor, but this library is pretty out of date by now so I'm not sure how well it works. It should be relatively easy to create something like this though.
I followed the OCR text reader guide on Codelabs (https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#0).
Now, I would like to save, a single portion of the text that I am scanning.
I tried with reducing width, and height of the preview; but it doesn't work, the APK crashes (at least on the only device I have to test it).
I am completely new to Java, and Android development, but my Internship mentor said to do this; completely alone, with zero help (as no one in the company knows about development).
So, the app opens, it recognizes text. Now, I would like to to know if there is a way to take that text, and save it (XML or TXT file).
I tried to look in the code, and see if at some point, the text read is saved in a variable or something; but it looks like a live preview, done trough the Google's dependencies (or a similar process).
I am not sure, but this might be off topic, as it is similar to an open question, but I am giving details on what I have done so far, and what I have tried.
Thanks.
The detected text is displayed in the OcrGraphic.draw(Canvas) method. There, it is returned as a TextBlock. You can call textBlock.getComponents() to get the lines and textBlock.getComponents() again to get each individual word (as a Text object).
Then you can convert it to a string and write the text to a file if you would like.
I have an array of strings which are in latin and have some letters which are turned into "?", I need them to display correctly.
String[] asd= {"Srećni nikad ne razmišljaju o sreći."};
in "asd" I have strings which I need to display correctly in TextView on my android device, but every "ć", "š" turns into "?".
textView.setText(asd[0]);
I am using Android Studio. Thanks
In Android Studio there is two options for encoding you need to check
1- your project encoding
2- your IDE encoding
you will find them under setting
Please make sure also not to hard code any strings you have to put them in string xml files
Try using Unicode, here is a table for your convenience ;
http://unicode-table.com/en/#00E8
And chech this question, it may help;
Unicode characters not displayed in TextView.setText
You are supposed to put strings like that into your XML and get them from there. It's a good idea too, since that allows you to have several languages, yet using the same code. Read more here
I am developing a native app which consists of some mathematical formulas.
Formulas will be like.........
I want to display such formulas in my application, but i don't how to use these special characters in Android. I want to display each formula individually in a list view...... If i am copying formula & if i am setting text to text view means it is showing like
txtv.setText("\\cos^2\\theta + \\sin^2\\theta = 1\\! ");
and getting output in the same pattern. So, can anyone help me how to use these mathematical special characters in Android..
Sorry, there are not a lot of different solutions..
There are no 'magical answer", here are some different ways to achieve what you want.
1) Using a webview with some Javascript
2) using a server to produce a picture of the formula.
3) Using a 9.png file embededd in your app with the square root symbol and display it as textview background
4) Drawing a canvas with all your text and symbols
5) using Hexadecimal code: http://htmlhelp.com/reference/html40/entities/symbols.html
http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html
6) Maybe other ideas, but definitely no way to achieve a 300 formula listview in a easiest way.
This one seem quite good and works in Android without any issue: http://mathscribe.com/author/jqmath.html
Edit:
You can run this inside a WebView, you don't need any webapp.
I'm trying to add a line break with the Find function in eclipse - What I want to do is put a line after each method in all my classes [I liked them all close together but now its hard to read through]. so I figure theres 2 ways to do this.
1. Find all with "public" and change to "\npublic", \n being the new line in a string to give you the idea of what I mean.
2. A convenient eclipse shortcut that separates all the methods in a class with an empty line.
Any ideas on how to achieve this? I'll be happy as long as it works and I don't have to go through every method in the project myself and push enter .-.
For #2, you can set the Eclipse auto-formatter to do so for you.
Look under the Preferences panel; in the left side (tree), select Java Code Style (click the arrow to expand the section), then Formatter. You can then decide to use a single formatting style for all of your projects, or check the box to apply a special set of formatting rules to just the current project. Some of the options include where to locate whitespace and newlines.
You can also use the “Save Actions” panel to re-apply the same formatting rules every time you save your files. Personally, I use (and team members as well) this method, to ensure that the formatting for the files is always consistent. By mechanically reformatting in this way, changes to the file will always show up “properly” in Subversion/Git — I don't accidentally have whitespace-only changes being introduced into files showing up as “false positive” changes.
Check box 'Regular Expressions' and use '\R' for Linebreak in the 'Replace with' box in eclipse
configure the auto-formatter its a bit of work for the first time but its worth, when ever you get ugly formatted code you can fix this in seconds ..