eclipse Android GUI 帮助:如何创建自定义按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5686656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:11:07  来源:igfitidea点击:

Android GUI Help: How to Create custom buttons

androideclipseuser-interface

提问by ultimatenirvana

I was wondering how you can create buttons like the ones at the bottom of the screen and the home button at the top?

我想知道如何创建像屏幕底部的按钮和顶部的主页按钮这样的按钮?

enter image description here

在此处输入图片说明

回答by Bruno Tereso

Quite hard to understand if you have doubts about button design and states or button position. If it's a design issue, you should create your button states on your favorite software, as example, photoshop. Then, in your android layouts you point your button background src to a drawable XML containing all button states.

如果您对按钮设计和状态或按钮位置有疑问,则很难理解。如果是设计问题,您应该在您喜欢的软件(例如 photoshop)上创建按钮状态。然后,在您的 android 布局中,您将按钮背景 src 指向包含所有按钮状态的可绘制 XML。

Example XML for button:

按钮的 XML 示例:

    <Button android:id="@+id/back"
            android:layout_width="184px" android:layout_height="44px"
            android:background="@+drawable/back" />

After this, you need your custom picture for the button, and the button XML on your drawables folder, here's the XML you need for your button:

在此之后,您需要按钮的自定义图片,以及 drawables 文件夹中的按钮 XML,这是按钮所需的 XML:

    <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/button_pressed" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/button_focused" /> <!-- focused -->
     <item android:drawable="@drawable/button_normal" /> <!-- default -->
 </selector>

Follow up on: http://developer.android.com/reference/android/widget/ImageButton.html

跟进:http: //developer.android.com/reference/android/widget/ImageButton.html

回答by anticafe

The title bar you mentioned about is called "Action Bar"

您提到的标题栏称为“操作栏”

You can learn how to implement it here:

您可以在此处了解如何实现它:

Regards.

问候。