How to Add Magnifier API in Android App?
Follow the simple steps below to add the magnifier API to your android app.
Step #1: Calling the Magnifier View onto an object
We will first add the magnifier object on the class in which we want the magnification to happen, like:
Java
TextView gfgView = findViewById(R.id.gfgView); Magnifier gfgMagnification = new Magnifier(gfgView); gfgMagnification.show(view.getWidth() / 3 , view.getHeight() / 2 ); |
Step #2: Changing the background
To change your magnification background with a different theme, we will use the functions of this API:
Java
// Use the color in the Parse Color Here. gfgTextView.setBackgroundColor(PARSE_COLOR_HERE); |
The content of the magnifier is outdated since a portion of the view with the previous background is still visible, assuming the background color can be seen within the magnifier.
GeekTip #1: Use the update() function to update the content.
Step #3: Dismissing the Magnified View
When you have done away with your magnification, you can use this method to dismiss the view and go back.
Java
gfgMagnification.dismiss(); |
GeekTip#2: The coordinates supplied to display() are forced into the view’s viewable area if they require copying external content.
How to Use Magnifier API in Android?
You may have encountered a magnified effect when you have scrolled over text view in recent versions of Android, and have wanted to integrate the same functionality in your app as well. In this article, we will learn how to work towards implementing the same in your app. The magnifier widget, which is accessible in Android 9 (API level 28) and higher, is a fictitious magnifying glass that shows an enlarged version of a selected View through an overlay window that serves as the lens. The functionality enhances the text input and selection user experience by allowing users to precisely position the cursor or selection handles while using the magnifier by displaying the magnified text in a pane that moves along with their fingers.