简体   繁体   English

如何在Android App的底角向Google Play商店添加按钮?

[英]How to add button to Google Play store in bottom corner of Android App?

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). 我正在组装一个简单的Android应用程序,我想在屏幕的底角之一上添加一个按钮,当用户按下时将其带到应用程序的GooglePlay页面或我的GooglePlay个人资料页面(无论我事先决定哪种方式) )。

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 ? 在对指南进行搜索之后,我发现下面的链接基本上显示了我想要的内容并提供了执行该脚本的脚本,问题是我不确定我需要将该脚本放置在哪个文件中以及在其中的位置确切地说,我是否将此脚本放在AndroidManifest.xml文件中的某个位置? The layout main.xml ? 布局main.xml?

http://www.appsgeyser.com/blog/tag/customized-code/ http://www.appsgeyser.com/blog/tag/customized-code/

Any help would be appreciated I'm new to this Android App stuff. 任何帮助将不胜感激,我是这个Android应用程序的新手。

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. 在您的情况下,它是布局文件夹中的main.xml。 Then your main.xml should look similar to this one: 然后您的main.xml看起来应该与此相似:

<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: 在您的MainActivity中,向此Button分配一个OnClickListener

@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. 在onClick内,您可以使用URL创建一个Intent ,该URL显示您的开发者页面或Play商店中的应用。

If you'd like to have an image rather than just text, you can also use ImageButton . 如果您想拥有图像而不只是文本,还可以使用ImageButton

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Google Play 商店发布超过 100 MB 的 Android 应用程序 - How to publish Android App above 100 MB on Google Play store android-更新按钮未显示在Google Play商店中 - android - Update button is not displaying on Google Play Store 如何在JavaFX中将按钮对齐到右下角? - How to align a button into the bottom right corner in JavaFX? 如果应用使用网络浏览器链接,如何通过Google Play商店的Android TV资格? - How to pass Google Play Store eligibility for Android TV if app uses web browser links? Android应用问题-如何在Play商店中加载应用条目 - Android app issue - how to load app entry in play store Android应用中的停止/播放按钮 - Stop / Play Button in Android app 如何在android的左上角和右下角创建圆角半径? - How to create corner radius in top left and bottom right in android? 如何将Google Play服务依赖项添加到Android Makefile中? - How to add Google Play Services dependency to Android makefile? 是否有可能在运行时可靠地检测安装了Android应用程序(Google Play或亚马逊市场)的商店? - Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)? 如何配置 Android App Bundles 以在 Google Play 上发布 apk (PWA)? - How to configure Android App Bundles to publish apk (PWA) on Google Play?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM