how to set drawable background of edit text programmatically - java

Hello every one I am new in the android studio I have a picture in my drawable folder and I want it to save the picture as a background of the edit text programmatically for this I write a code bellow but its not working and it showing a red line error
here is my code.
edit_text.setBackground(R.drawable.background1);
any idea for this how I will write it
please don't suggest me another post as I am new here.

You should retrieve the background drawable using ContextCompat.getDrawable method:
edit_text.setBackground(ContextCompat.getDrawable(this, R.drawable.background1));

Related

In Android Studio How to make Validation for imageview?

How to make validation in android studio for image view.
E.g. I have button when i click on button it open a gallery and i select image it comes in image view but how to set that if someone not upload image it will show message till not upload image in image view
Thanks.
The uri or bitmap that you use to save the image, use it in sharedPreferences. So that when the default value is null user will get the message but when you add a new image it will overwrite the default value of sharedPreferences and hide the messgae.

Zoom ImageView in android like Instagram

How can I zoom ImageView like Instagram. I mean changing the size of imageview, not zooming the image inside the Imageview.
For zooming the image inside the Imageview, there are a lot of samples but I want something like Instagram image zooming
Any code or hint? Thanks.
I recommend Zoomy, very simple and functional.
Just add the following to your current ImageView:
Zoomy.Builder builder = new Zoomy.Builder(this).target(mZoomableView);
builder.register();
I would recommend these two libraries:
PhotoView
ImageViewZoom
For PhotoView, you just have to create an attacher and "attach" it to your ImageView.
Some code
// After getting your imageImage view, attach it like the following
PhotoViewAttacher yourAttacher = new PhotoViewAttacher(yourImageView);
With just this code, you'll be able to zoom in/out/whatever on yourImageView. Check the links above for more details.
EDIT
Instagram has changed a lot since this answer was posted, and the libraries I recommended above might not provide the experience you are looking for.
thanks
I have added this to my gradle.build
compile 'it.sephiroth.android.library.imagezoom:imagezoom:2.2.5'
and then using this view
<it.sephiroth.android.library.imagezoom.ImageViewTouch
android:id="#+id/mp3Image"
android:adjustViewBounds="true"
android:layout_width="346dp"
android:layout_height="356dp"
android:scaleType="fitCenter" />
and the below code, the zoom came to my app
myImage = (ImageViewTouch) findViewById(R.id.mp3Image);
myImage.setDisplayType(ImageViewTouchBase.DisplayType.FIT_IF_BIGGER);

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

Create simple text popup for textview

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

Error in Second Activity "cannot be resolved or not a field"

I would like to create a simple android app which will have two screens
one is MainActivity
other is SecondActivity
After creation of second activity I am getting an error activity_second cannot be resolved or not a field even though activity_second XML exist don't how to resolve.
setContentView(R.layout.activity_second);
Above line showing error
please go through the images to get a clear picture of what the errors i am facing
SecondActivity.java Image
Second Activity XML Image
How would i solve the above errors
Thanks in Advance
Not a big problem..you have given names of your drawable images wrong so your R.java not buliding successfully.
ie android only allows a-z,0-9 in identifiers for drawable images so make names of drawable in lowecase
for example: IMAGE1.png is wrong
change to image1.png and your R.java will build successfully and your layout will be recognize.
setContentView(R.layout.activity_second);
Hope this helps.
Try to import com.example1.hello1.R in SecondActivity.class

Categories

Resources