Create simple text popup for textview - java

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);

Related

Java: How to add a png image to the middle of a sentence

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));

Edit text view with image and text wrapped around image

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);

How to change the action bar color and open a file on click?

I'm working now on an app for Android and there are two things that I don't know how to do.
I want to change the colour of the action bar at the request of the user, so I want to change it dynamically. I see some answers that say that I need to use:
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004D40")));
But for some reason, it does not work for me.
I've added to my app option to download a file, but I do it in an unusual way so it does not create a notification when the download is complete. I want to give my user an easy way to get to the file. Can I create a button that opens the file when clicked?
Thanks!
1) For that I would recommend you having Example here Toolbar View and set it as your Actionbar. Just add this view at the top:
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
And then in Activity
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
After this you can change everything you want to the view myToolbar. Set background color etc. It will work. Using just Actionbar is old and depricated approach.
2) Yes you can, it is like opening new Activity with intent. Android has some inbuilt Intent Action Type which helps you to Open or View specific files, but for this you need to know which type of file you are going to handle.
Suppose If you have file type which categorized in document type you can use,
ACTION_OPEN_DOCUMENT with specific MIME_TYPE (Android 4.4 or Higher)
or If you going to handle some media file (Audio/Video)
you can use,
ACTION_VIEW
To identify MIME_TYPE of specific file you can use function
guessContentTypeFromName (String url)Link
Or getMimeTypeFromExtension(String extension)Link
Hope this helps :)
You can't change the color because you should call getSupportActionBar() and it's also for api >11;
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.black)‌​));
or
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004D40")​));
About your second question, we need more info and your code where you download file. You totally can access files onClick but you need to know the file type and the directory where you store the files and target api to check runtime permissions for example
I suggest you ask another question with all your code and this info

Display pdf image on click that is scrollable in another page

What I want to happen is that when a button is clicked, the user gets sent to another page and then a pdf file is openly displayed (the contents of it) and it is scrollable.
I have absolutely no clue how to go about this, which is why I am posting it in another question because I am aware that there is probably an answer that already explains how to do this, but I am so new to it I do not have any clue how to start!
The software is for an app (android studio), so I cannot use javascript to do it ( I do not think)
It is not a duplicate of that because I really have no clue how to solve the problem as I am too 'beginner-like' and also the fact that that article shows how to do it with internet and I cannot do it with internet for my application
I have done similar case in past. What I did is, I load a image by image from the pdf to android ImageView by passing the page number. I did this using Debenu PDF Library For Android
When User click your first Button Open separate activity and get the first page as a Image by passing page number to the pdf library inside the OnCreate method of Activity
If you need more help, feel free to ask..
There are already detailed answers on Stackoverflow: For instance:
How to open/display documents(.pdf, .doc) without external app?
In order to go to a new Page you use :
startActvity(new Intent(context, ActivityName.class));
The new Activity holds an WebView
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Then you can use
WebView wv = (WebView)findViewById(R.id.webView);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.loadUrl(doc);
Check this, Hope it will help -
1) Render a PDF file using Java on Android
2) https://github.com/jblough/Android-Pdf-Viewer-Library

Facebook LikeView change button size

I am using a LikeView in my android application and want to change the button size. Changing the view's size using layout parameters or the width/height at addView() does not help.
I'm using libGDX and have never worked with XML + libGDX, so a way to do it with code only would be nice!
Does anyone know how to do this? Currently I use the following code to create my LikeView:
likeButton = new LikeView(application);
likeButton.setLikeViewStyle(LikeView.Style.BUTTON);
likeButton.setX(x);
likeButton.setY(y);
likeButton.setObjectId(LIKE_URL);
likeButton.setVisibility(View.GONE);
application.layout.addView(likeButton,width,height);
likeButton.invalidate();
application.layout is a RelativeLayout
Try to create your LikeView from XML (or inflate this layout at runtime):
<com.facebook.widget.LikeView
android:id="#+id/button_like"
android:layout_height="31dp"
android:layout_width="wrap_content" />
I finally fixed it using setScale on the view. It's not the most elegant solution, but it does the job.
likeButton.setScaleX(1.8f);
likeButton.setScaleY(1.8f);

Categories

Resources