2015-11-07 90 views
0

我在制作一个简单的Android应用程序,并且想要在屏幕底部的一个角落添加一个按钮,当用户按下这个按钮时,他们会将它们带到应用程序的GooglePlay页面或我的GooglePlay个人资料页面(无论我如何选择之前)。如何将按钮添加到Android应用程序底部的Google Play商店?

在做了一些这样的搜索后,我发现这个链接基本上显示了我想要的,并给出了一些脚本来做到这一点,问题是我不完全确定哪个文件我需要放置此脚本以及它究竟在哪里,我把这个脚本放在AndroidManifest.xml文件的某个地方?布局main.xml?

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

任何帮助,将不胜感激我是新来的这个Android应用程序的东西。

回答

0

首先,你需要一个Button添加到您的布局应包含按钮。在你的情况下,它是布局文件夹中的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你分配一个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创建一个Intent与网址,显示你的开发人员页面或Play商店中的应用。

如果你想有一个形象,而不仅仅是文字,还可以使用ImageButton

+0

感谢您的回复反对!这就是我一直在寻找的东西,只需要一些帮助就可以了。我到底要在哪里粘贴第一个按钮代码到您列出的Main.xml中,以便让此按钮位于应用程序的右下角?我把它放在一个地方,它可以工作,但它在应用程序屏幕的中间。那么当你说“在你MainActivity”你谈论MainActivity.java文件吗? – gamertrial1

+0

*更新*我喜欢我的应用程序屏幕的底部最后1/6,专门用于Admob横幅我希望我能以某种方式让此按钮坐在该部分上,然后当Admob横幅出现时他们覆盖它直到广告关闭管他呢。但似乎我只能把这个按钮放在那个部分或者正好在(我现在正在做的)之下。但是,按钮停留在屏幕的左下角,并且如果中间对齐,视觉效果会更好,我可以做到这一点吗? – gamertrial1

+0

我已经想出了如何将按钮放在main.xml文件中的大部分。但我不知道在MainActivity.java文件中放置onclick代码的位置。有什么帮助吗?我是否只用一个URL替换文本“linkToYourDeveloperPage”? – gamertrial1

相关问题