【问题标题】:How to create round cornered textbox in Basic4Android如何在 Basic4Android 中创建圆角文本框
【发布时间】:2014-05-26 03:30:14
【问题描述】:

我正在尝试在 Basi4Application 中自定义应用程序的 UI。使用它才 3 天。所以我需要帮助来定制 UI。到目前为止,我已经做出了这些改变并且还在学习。任何人都可以向我指出任何有关在 Basic4Android 中自定义 UI 的教程或网站。 默认情况下,用户名 Edittext 显示如下,希望看起来像这样。请参考下图。 有人请帮帮我。提前致谢。

【问题讨论】:

    标签: android basic4android


    【解决方案1】:

    在drawable文件夹中创建xml文件-

    rounded_corner.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!-- res/drawable/rounded_edittext.xml -->
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:padding="10dp"
        android:shape="rectangle" >
    
        <solid android:color="#FFFFFF" />
    
        <corners
            android:bottomLeftRadius="3dp"
            android:bottomRightRadius="3dp"
            android:topLeftRadius="3dp"
            android:topRightRadius="3dp" />
        <stroke
              android:width="2dp"
            android:color="#4D4D4D"
            ></stroke>
    
    </shape>
    

    & 在你的布局代码中-

    <TextView
                android:id="@+id/Name"
                android:layout_width="fill_parent"
                android:layout_height="40dp"  
                android:background="@drawable/rounded_corner"
                 />
    

    【讨论】:

    • 您可以设置任何您想要的高度值。比如 40dp,50dp .. 或 WRAP_CONTENT
    【解决方案2】:

    试试下面的代码:-

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <solid android:color="@color/white_lite" />
    
    <stroke android:width="1dp"
        android:color="@color/purple_dark"/>
    
    </shape>
    

    <?xml version="1.0" encoding="utf-8"?>
    <!-- res/drawable/rounded_edittext.xml -->
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:padding="10dp"
        android:shape="rectangle" >
    
        <solid android:color="#60FFFFFF" />
    
        <stroke
            android:width="2dp"
            android:color="#1c6aaa" />
    
        <corners
            android:bottomLeftRadius="10dp"
            android:bottomRightRadius="10dp"
            android:topLeftRadius="10dp"
            android:topRightRadius="10dp" />
    
    </shape>
    

    【讨论】:

      【解决方案3】:

      rounded_corner.xml

        <?xml version="1.0" encoding="utf-8"?>
           <shape
             xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
      
        <!-- view background color -->
       <solid
          android:color="#a9c5ac" >
      </solid>
      
      <!-- view border color and width -->
      <stroke
          android:width="3dp"
          android:color="#1c1b20" >
      </stroke>
      
      <!-- If you want to add some padding -->
      <padding
          android:left="4dp"
          android:top="4dp"
          android:right="4dp"
          android:bottom="4dp"    >
      </padding>
      
      <!-- Here is the corner radius -->
      <corners
          android:radius="10dp"   >
      </corners>
      </shape>
      

      并将此可绘制对象保留为要保留圆角边框的视图的背景。让我们保留它作为 LinearLayout

          <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Name"
              android:gravity="center"
              android:padding="5dp"/>
      
      </LinearLayout>
      

      【讨论】:

      • 我没有使用 Eclipse。我正在使用 Basic4Android 应用程序来制作应用程序。如何在该应用程序中完成。
      【解决方案4】:

      默认的编辑文本在不同的手机和模拟器中看起来不同。例如:尝试旧的模拟器,你会得到漂亮的圆形矩形。虽然标签很容易四舍五入,但编辑文本却不是。您可以使用 9 个补丁图像进行自定义。请参阅 B4A 论坛。论坛浏览是免费的。只有库下载受到限制。

      【讨论】:

        【解决方案5】:

        我应该向您介绍 B4A 论坛,那里有 B4A IDE 的所有知识库。 http://www.basic4ppc.com/android/forum/

        那里也有很多与 UI 相关的讨论,只是指那里的一些随机教程:

        http://www.basic4ppc.com/android/forum/threads/how-they-do-1.20878/ http://www.basic4ppc.com/android/forum/threads/how-they-do-2.20970/ http://www.basic4ppc.com/android/forum/threads/how-they-do-3.21137/

        ...还有更多。

        对于编辑文本,您可以使用 ColorDrawable 或 9Patch 图像。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-07-29
          • 2021-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-17
          • 1970-01-01
          相关资源
          最近更新 更多