相关疑难解决方法(0)

如何使用XML样式在Android中创建自定义按钮

我想通过使用XML样式制作这种按钮[相同的背景和文本]颜色

在此输入图像描述

这只是一个例子,我想写一些其他文本,如:关于我

我还在使用Photoshop设计师创建的按钮

    <ImageButton
        android:id="@+id/imageButton5"
        android:contentDescription="AboutUs"
        android:layout_width="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view_pager"
        android:layout_centerHorizontal="true"
        android:background="@drawable/aboutus" />
Run Code Online (Sandbox Code Playgroud)

注意:我需要各种尺寸和形状的按钮

我不想在我的Android应用程序中使用任何图像,我只想使用XML

android android-widget

59
推荐指数
4
解决办法
25万
查看次数

水平居中两个按钮

我尝试将两个按钮(它们上面的图像工作正常)安排在一起,并将它们水平居中.这就是我到目前为止所拥有的:

<LinearLayout android:orientation="horizontal" android:layout_below="@id/radioGroup"
              android:layout_width="wrap_content" android:layout_height="wrap_content"
              android:layout_gravity="center_horizontal|center">
    <Button
            android:id="@+id/allow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/radioGroup"
            android:layout_gravity="center_horizontal"
            android:drawableLeft="@drawable/accept_btn"
            android:text="Allow"/>
    <Button
            android:id="@+id/deny"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/allow"
            android:layout_below="@id/radioGroup"
            android:layout_gravity="center_horizontal"
            android:drawableLeft="@drawable/block_btn"
            android:text="Deny"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

不幸的是,它们仍然与左侧对齐.任何帮助表示赞赏!伊夫

编辑:

不幸的是,迄今为止没有任何评论或建议有效.这就是我尝试使用RelativeLayout提供简化的完整布局的原因:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_centerHorizontal="true">
    <TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
          android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <Button
        android:id="@+id/allow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/TextView01"
        android:text="Allow"/>
    <Button
        android:id="@+id/deny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/allow"
        android:layout_alignTop="@id/allow"
        android:text="Deny"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了LinearLayout和Button元素中的所有属性组合而没有运气.还有其他想法吗?

layout android

48
推荐指数
6
解决办法
9万
查看次数

标签 统计

android ×2

android-widget ×1

layout ×1