I am building a rich text editor.
I have implemented text formatting like bold italic etc and also paragraph formatting like blockQuote. Now I would like to add images in editor and text should wrap around it.
I have implemented all these using SpannableString() and Spanned() and StyleSpan().
I can add image to a line using ImageSpan(), but that add it inline and its just there in place of a character
, what I want is to insert it in paragraph and rest of text should wrap around it. I am able to add image at the beginning of text by following code.. but I cannot align it center and right.
SpannableString string = new SpannableString("Text with icon and padding");
string.setSpan(new IconMarginSpan(bitmap, 30), 0, string.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
How to do it ? any example? or what procedure to follow?
you can fulfill your requirement like below:
you can set your image in imageview and your text in Html.fromHtml("here put your text")
gradle file:
compile 'com.github.deano2390:FlowTextView:2.0.5'
your XML layout:
<uk.co.deanwild.flowtextview.FlowTextView
android:id="#+id/ftv"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="400dip"
android:padding="10dip"
android:src="#drawable/android2"/>
</uk.co.deanwild.flowtextview.FlowTextView>
your java file:
FlowTextView flowTextView = (FlowTextView) findViewById(R.id.ftv);
Spanned html = Html.fromHtml("here put your text");
flowTextView.setText(html);
you may get help by this link https://github.com/deano2390/FlowTextView also
I hope it help you..!
As per details given by you, It seems you might be using native EditText or you are trying with your custom EditText. Please provide this details to get exact solution of your query.
Apart from that, To build Rich Text Editor with the features mentioned by you (like Bold, Italic, Quote and Images etc), you can use this library RichEditor for Android: https://github.com/wasabeef/richeditor-android. It provides many features which may interest you.
Try with:
EditText text = (EditText)findViewById(R.id.text);
text.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.check_box), null);
Related
It should look like this:
I'm specifically using android studio. I currently have a textview and my text in the strings.xml file, but I understand there are other ways of doing the code. I have several paragraphs to write, so I figured this would be the best place to insert the text. I will need to include an image, a button, and links straight into the sentences I'm writing. (Any advice for each of those would be helpful) But, my first issue is that I don't know how to add the image into the middle of the sentence. All relevant posts are incomplete or outdated.
I would suggest if you wish to display large amount of text then use something like WebView with some html template engine.
To achieve this you need to use setCompoundDrawablesWithIntrinsicBounds() method of TextView. Heopfully this will help you.
Or you can use **SpannableStringBuilder ** for this to get. I hope this will help you.
UPDATED: Here sample is available. I am attaching link as well. It will help you in your implementation
https://stackoverflow.com/questions/15352496/how-to-add-image-in-a-textview-text
I have implemented this type of code in my app but I was used dependency which I describe here...
Implement this dependency in your build.gradle file
implementation 'org.sufficientlysecure:html-textview:4.0'
and then write this line in your build.gradle(Root level) or on the settings.gradle file
repositories {
jcenter()
}
Layout.xml
<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="#+id/textView"
android:textAppearance="#android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="13dp" />
In your Activity.java file in OnCreate Method
TextView textView;
textView = (TextView) itemView.findViewById(R.id.textView);
textView.setHtml("<b>Hello</b> this is my Text <span/> <img src="yourimage.jpg"> <span/> Another Text, new HtmlHttpImageGetter(myHolder.question));
I have a simple app with jokes. There are buttons where I set the text with this code:
bt_barjokes.setText(getString(R.string.bar_jokes)+ " ("+barjokes.size()+")");
Works perfectly and it gives the correct title and size of the used Arraylist: Bar Jokes (55)
The problem is I want to change the color and font size of (55):
("+barjokes.size()+")")
I have tried several of the suggested solutions in this forum but can't get it to work.
You can use ForegroundColorSpan to change text color, and AbsoluteSizeSpan or RelativeSizeSpan to change font size.
You can look #xizzhu 's answer, its ok additionally you can use SpannableString or Html.fromHtml
setText(Html.fromHtml("<font color=#343434>" +"<small>"+ "Little Black Text" +"</small>"+
"</font>"+"  "+"<font color=#123456>" +"<big>" +"Big Blue Text" +"</big>"+ "</font>"));
#Edit : If you wanna use this in your button add this line in xml like: android:textAllCaps="false"
You can use : <small> or <big> , tested in Toolbar:
and in Button, its looking like :
I'm new to android and started to learn java, i found an app called learn java and i notice the popup appear when i tap a text view,here is a screen shot
is there a simple way to do this in android studio like textview.showpoponupclick("text") or i have to invent it,i saw some tutorials to make .XML and a lot of coding, but i only want to show some text similar to the edittext.setError(); . and sorry for my English.
Do refer some external libraries like this.
As sample use its layout XML like here provided
<com.nhaarman.supertooltips.ToolTipRelativeLayout
android:id="#+id/activity_main_tooltipRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
And create a tooltip view from java code
ToolTipRelativeLayout toolTipRelativeLayout = (ToolTipRelativeLayout) findViewById(R.id.activity_main_tooltipRelativeLayout);
ToolTip toolTip = new ToolTip()
.withText("A view")
.withColor(Color.RED)
.withShadow()
.withAnimationType(ToolTip.ANIMATIONTYPE_FROMTOP);
myToolTipView = toolTipRelativeLayout.showToolTipForView(toolTip, findViewById(R.id.activity_main_redtv));
myToolTipView.setOnToolTipViewClickedListener(MainActivity.this);
In my app i want to convert my english font into hindi, for that i did localization. that is not supported for lower versions(i.e 2.3). Then i downloaded "shusha.ttf" file and added to assets/fonts folder. Then i set the typeface for a textviews. Like this i am able to convert the english font to hindi. but when i get the text from the text view it is not showing in Hindi(getting the english font). i am using that text to send the mail through gmail.
If any body have idea about this please give me a suggestion.
This is my Code
t = ((TextView)findViewById(R.id.textView1));
t2 = ((TextView)findViewById(R.id.textView2));
Typeface Hindi = Typeface.createFromAsset(getAssets(), "fonts/shusha.ttf");
t.setTypeface(Hindi);
t.setTextSize(20);
String hello=" Hyderabad, Andhra Pradesh, India ";
t.setText(hello);
String lang=t.getText().toString().trim();
t2.setText(lang);
Instead of using and playing with font, use UNICODE characters for hindi words. I had done it for a project of mine and it works great.
You have to change the font of the text of text view.
First put the font in your asset folder.
Then in your java file add code like this to change your font:
Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),
"shusha.ttf");
TextView digital= (TextView) findViewById(R.id.your_textView);
digital.setTypeface(myTypeface);
Put shusha.ttf in your asset folder of your project.
This will might help you.
Create styles in values/styles like,
<style name="MyStyle" parent="#android:style/Theme">
<item name="typeface">font_in_assest.ttf</item>
</style>
Here, font_in_assest.ttf is the font you placed in your assests/fonts.
Then assign the style for you view,
<TextView
android:id="#+id/title"
style="#style/MyStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
It will be helpful for you..
I have an edittext and I would like to paste some text in it. I can copy the text from some web page but I am not able to paste the text in my edittext control.How can I enable my edittext to paste some text.Here is my main.xml for edittext ;
enter code here
<EditText
android:id="#+id/enter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight= "2"
android:scrollbars="vertical"
android:textColor="#color/black"
/>
Thanks
This is on Android 4.4.2 Samsung S4;
Documentation for TextView says that:
To allow users to copy some or all of the TextView's value and paste
it somewhere else, set the XML attribute android:textIsSelectable to
"true" or call setTextIsSelectable(true). The textIsSelectable flag
allows users to make selection gestures in the TextView, which in turn
triggers the system's built-in copy/paste controls.
There is also another Textview attribure called android:cursorVisible which determines if the system should be invoked about the copy/paste callbacks.
By default I believe both of these are true and selection/copy/paste mechanics are already enabled. I could not change that behaviour by using android:textIsSelectable="false" but if I set android:cursorVisible="false" initially you can't paste anything inside the EditText. Only after you type something in, cursor and selection behaviour becomes enabled again. Maybe this should be handled inside the code rather than in the layout xmls, or it might be related to android:inputType which also did not make a difference for me.
So try setting android:cursorVisible="true" in your EditText's layout xml if paste is not enabled by default.
According to your problem if you copied some data any where in your system and you want to paste it in some specific variable, like Edit TextBox, Textview etc, then this code will surely help you.
ClipboardManager clipMan = (ClipboardManager)getSystemService(v.getContext().CLIPBOARD_SERVICE);
myEdtTxt.setText(clipMan.getText());
Note:- here the clipMan object will store the data whenever copied process take place and we will return that data from that object and will set it,
To enable the standard copy/paste for TextView, U can choose one of the following:
Change in layout file:
Either add below property to your TextView
android:textIsSelectable="true"
and In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
if fragment try with
mContext.myTextView.setTextIsSelectable(true);
And long press on the TextView you can see copy/paste action bar.
Try setting the inputType="text" for the EditText field