I'm putting together a simple Android app and I wanted to add a button to one of the bottom corners of the screen that when the user presses brings them either to the app's GooglePlay page or my GooglePlay profile page (whichever way I decide before hand).
After doing some searching on a guide for doing this I found this link below which basically shows what I want and gives some script for doing it, the problem is I'm not exactly sure which file I need to place this script and where in it exactly, do I put this script somewhere in the AndroidManifest.xml file ? The layout main.xml ?
http://www.appsgeyser.com/blog/tag/customized-code/
Any help would be appreciated I'm new to this Android App stuff.
First, you need to add a Button to your layout which should contain the Button. In your case it's main.xml from the layout folder. Then your main.xml should look similar to this one:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--other Views-->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:text="My Apps" />
</RelativeLayout>
In your MainActivity you assign an OnClickListener to this Button:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open up browser or play store with the provided link
String url = linkToYourDeveloperPage;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
}
Inside onClick you create an Intent with an url which shows your developer page or your apps in the Play Store.
If you'd like to have an image rather than just text, you can also use ImageButton .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.