Add Link into Android App

Reading Time: 3 minutes

Once when you made your initial application with AdMob in it you need to put some functionality to it. If we make application for calculation of greatest common divisor, we can put in app→res→layout→activity_main.xml (design view) some large text widgets, some number text fields and one button.

We need now to declare in app→java→cirvirlab.gcd→ inside the declaration of public class MainActivity extends AppCompatActivity text view control, for example txtN.


Next step in giving functionality to your app is to map text view control on graphical object text field. So again in app→java→cirvirlab.gcd→ in function onCreate map this text view on text fields.


protected void onCreate(Bundle savedInstanceState) {



txtN = (TextView)findViewById(;

txtM = (TextView)findViewById(;

Now, go to text mode of app→res→layout→activity_main.xml

In button, declare function on event onClick


And then write function in app→java→cirvirlab.gcd→ Initial code just for checking functionality can be as follows:
public void calculateGCD(View view)

String str_message = “Welcome”;




Once, when functionality is tested, use try{} catch(Throwable e){} structure to write safe code:

public void calculateGCD(View view)



int x = Integer.valueOf(String.valueOf(txtN.getText()));

int y = Integer.valueOf(String.valueOf(txtM.getText()));

int N, M, R;

if( x > y ) {N = x; M = y;}

else { N = y; M = x; }

if( (N>0)&&(M>0) )


R = N % M;

while( R > 0)


N = M;

M = R;

R = N % M;





catch (Throwable e)




Now, we can add link into android app as following.
On inserted TextView control put the next code:
app→java→cirvirlab.gcd→, in function onCreate(Bundle savedInstanceState):

txtLink = (TextView)findViewById(;
String linkedText = “Read more <a href=’’>on the blog</a>”;

And the final touch is to change default icon in android app. Path of that icon is something like:

E:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root\res\mipmap-xhdpi\ic_launcher.png

Put there your new app icon in png format with dimension 96X96 in pixels. Then go to app→res→mipmap then right click new→Image Asset and browse to your new app icon.


Your application is now ready to be launched!

External links:

Add link into android app on Stackoverflow
Change icon in android app on Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *