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

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="😂" />

Related

How to format xml and java code as text inside TextView

I am creating an Android Tutorial Application. I am planning to use Tabs to display the java and the xml code used for that topic.
I thought of using TextView and applying the Java and XML code as text to it.
However I am failing to format the Java code, plus I am not able to add xml as text at all as it has tags which are not supported.
Below are snaps from another App and the desired output is what I am looking for.
Any help or suggestions are welcomed.
You could display your Code in your TextView with HTML and style/format it with CSS.
Try this,
Suppose you have HTML code like this
<h2>Title</h2><br>
<p>description here</p>
Then in android you can use below code
TextView tvTrial=(TextView)findViewById(R.id.tvTrial);
String html="<h2>Title</h2><br> <p>description here</p>";
tvTrial.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Now any thing you want to display in you view you can store it the string and set it.

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

EditText Keyboard Inputtype issue

Which EditText Keyboard Inputtype combinaison can help me getting the following view. I try several issue but nothing. May be someone among you does already face this problem.
What i want to get is Numerics on the top and the possibility to switch to symbols and letters
What i want to get if a use touch the EditText must be as following
You may add the following attribute to your EditText in xml.
android:inputType="text|number"
However, some of the characters you input will not be appear - those which conflict with type number, like # = ! etc.
And in order to get search button (on bottom-right) in your virtual-keyboard, you may use:
android:imeOptions="actionSearch"
Update
Add the following to your EditText's xml and it will get you all the characters available in the keyboard under number inputmode:
android:inputType="number"
android:digits="0123456789.##$&*-=()!"':;/?"
If you want to support more characters then simply append their html name in android:digits.
Try this:
<EditText
android:layout_width="150dp"
android:layout_height="150dp"
android:inputType="PutHereNestedInputType"
/>
InputTypes
Hope it's help.

How can I add a source code with markup?

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.

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