How can I add a source code with markup? - java

Need to add it to textview, for example, standard java-code.

What do you exactly mean? You may want to change Typeface of TextView to monospace, this will make your TextView look similar to code block here at stackoverflow.
This font is monospace
Code to make it look like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"
android:text="This font is monospace" />
or in Java:
yourTextview.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);
Edit:
So, you need some Java code formatting library, the best would be if it returned result in HTML code, so it could be easily put into TextView.
I don't know if there is something like this for free, but here are few resources you may be interested in:
How to pretty print XML from Java?
Stand-alone Java code formatter/beautifier/pretty printer?
Edit2:
You may also use one of these JavaScript libraries:
http://alexgorbatchev.com/SyntaxHighlighter/
http://code.google.com/p/google-code-prettify/
along with custom WebView to show pretty formatted code.

Related

How do I print an Emoji as the text of a button?

I have tried hexadecimal values for the emoji in the text field but it did not work. I'm new to android studio 😂. Do I need to code it in? Or can I add it to the layout? Or both? Thank you
As we found out in the comments, the solution would be to put the code directly into the Java source e.g:
System.out.println("Hello world 😂");
Or the XML source:
<TextView
android:id="#+id/text_view_id"
android:text="😂" />

Border in text android not in text view and not shadow

I am trying to find an effect in text view android just like the below image.
This is a textview with border in the text:
Can anyone suggest me something to get this effect.
Thanks in advance :)
MagicTextView will do text outlines, amongst other things.
<com.qwerjk.better_text.MagicTextView
xmlns:qwerjk="http://schemas.android.com/apk/res/com.qwerjk.better_text"
android:textSize="78dp"
android:textColor="#ff333333"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
qwerjk:strokeColor="#FFff0000"
qwerjk:strokeJoinStyle="miter"
qwerjk:strokeWidth="5"
android:text="Magic" />
Note: I made this, and am posting more for the sake of future travelers than the OP.
It's borderline spam, but being on-topic, perhaps acceptable?
sourcehttps://stackoverflow.com/posts/10294290/edit

Unable to Set Text Size Using FlowTextView

I found a library which allows an app to wrap text around an image - however once implemented it changed the size of my text - how can the text size be increase when using this library?
android:textSize= has no impact on the text size.
Neither does:
FlowTextView titleTv = (FlowTextView) findViewById(R.id.titleTv);
((FlowTextView) findViewById(R.id.titleTv)).setTextSize(20);
https://code.google.com/p/android-flowtextview/
Example:
<com.pagesuite.flowtext.FlowTextView
android:id="#+id/titleTv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" >
In the short term a call to invalidate will probably get it working:
FlowTextView titleTv = (FlowTextView) findViewById(R.id.titleTv);
titleTv.setTextSize(20);
titleTv.invalidate();
However, I suspect you are using the JAR file right? It is quite out of date so I would recommend checking the source code out and using it as an android library project - setTextSize() should work properly then without needing a call to invalidate() (plus various other bug fixes etc).
Also - I never added the ability to set the text size via XML - wouldn't be too hard to add this though.
I checked the code of android-flowtextview and they have the text size hardcoded (check line 131 here). You have to change their source code or use the public method setTextSize(int).
Also, this link might help you, as seems that someone already did something as you are trying to do.
https://code.google.com/p/android-flowtextview/source/browse/trunk/src/com/pagesuite/flowtext/FlowTextView.java
There's a 'setTextSize(int)' method that should do exactly what you're looking for.
If you want to set it from XML, it's a little more involved. Since FlowTextView's constructors ignore the AttributeSet that gets passed in, you'll have to code this yourself. Follow guides like this: http://kotikan.com/blog/posts/2012/09/android-attributes to figure out how to add custom attributes to your views.

How to display the Sindhi Language fonts?

I'm making an app in my native language Sindhi.
Note: Sindhi language has 52 alphabets, like this
**ا، ب، ج،ف، ڪ**
I have installed Sindhi fonts on my PC, also I have the unicodes of Sindhi.
Problem
When I set text on my Button, like this
<Button
android:id="#+id/btnSindhiLessons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"
android:text="سنڌي سبق"
android:textSize="30sp" />
It shows perfectly on the code view but in design view it's showing something like this:
but on device or emulator it renders like this:
Notice that one letter is missing. I'm using Android 4.0.4
It's because Eclipse doesn't support Sindhi. While in your device it may support of it's 4.0+, I'm not sure it'll look good if you have an early android device.
check this out.
you are copy pasting the text directly to the code:
use uni code:
like this: \u0623,\u0623,\u0623,\u0623 for your every character
or
get supportive type face,which support sindhi.
one i know that is jameel noori nastaleek
hope it will solve your issue
Follow below steps :
Find best font for Sindhi
Place that font to your asset folder
Set this font as typeface to your button

Android string.xml error for every character I type

I am going through the android hello world tutorial, and have been stuck when trying to create an XML UI. For some reason, even on a new program, in which I have made no changes to the default build, it gives the error java.lang.NullPointerException after every character I type. I can't figure out why it is doing this, as I am just trying to edit the text between the Text I want to set it to say something other than what is set by default. However, even with a fresh build, no changes, and I just try to change the text within the xml tags, it still gives the error. What do I need to do to allow it to let me type? I am using the eclips IDE and the android sdk. I was able to do the first part of the tutorial that doesn't involve XML.
Just guessing, but I suspect you are doing something like the following:
<TextView android:text="#string/hello" />
and you are editing it to
<TextView android:text="#string/helloWorld" />
without creating a reference in res/values/strings.xml .
If this is the case, go to strings.xml and edit the proper string there, for example
<string name="hello">Hello World!</string>
becomes
<string name="hello">Hello everybody!</string>
Ok, I finally found the answer somewhere else, it was something wrong with how the file was created by default. I have to add the element xmlns:android as follows <resources xmlns:android="http://schemas.android.com/apk/res/android" />
Interestingly enough, the file will work if I type it one character at a time, dismissing the pop up with each keystroke. However the new element eliminates the pop ups. I am not sure why the error would pop up, yet the program still compile and run correctly on my avd. Oh well, if you have this error add the element and it goes away
I think in your typing contain UTF-8 not pure ASCII. You can change in eclipse by
in Ecipse IDE Window> preference> Under General tab, select workspace.
In text file encoding choose other, in these choose UTF-8 . It will be ok

Categories