簡體   English   中英

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

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

我正在組裝一個簡單的Android應用程序,我想在屏幕的底角之一上添加一個按鈕,當用戶按下時將其帶到應用程序的GooglePlay頁面或我的GooglePlay個人資料頁面(無論我事先決定哪種方式) )。

在對指南進行搜索之后,我發現下面的鏈接基本上顯示了我想要的內容並提供了執行該腳本的腳本,問題是我不確定我需要將該腳本放置在哪個文件中以及在其中的位置確切地說,我是否將此腳本放在AndroidManifest.xml文件中的某個位置? 布局main.xml?

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

任何幫助將不勝感激,我是這個Android應用程序的新手。

首先,您需要在布局中添加一個按鈕 ,其中應包含該按鈕。 在您的情況下,它是布局文件夾中的main.xml。 然后您的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>

在您的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); 
        }
    });
}

在onClick內,您可以使用URL創建一個Intent ,該URL顯示您的開發者頁面或Play商店中的應用。

如果您想擁有圖像而不只是文本,還可以使用ImageButton

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM