如何在android中制作自定义拨号盘xml设计..?

时间:2016-10-06 18:54:06

标签: android xml keyboard

我想在我的应用程序中使用字母设计自定义拨号盘。使用表格视图或网格视图更好吗??enter image description here

1 个答案:

答案 0 :(得分:0)

以下是example如何制作自定义拨号盘:

    <?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">

    <EditText
        android:id="@+id/EditTextPhoneNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/overlay_footer_background"
        android_layout_marginBottom="0"
        android:cursorVisible="false"
        android:textColor="@color/text_main"
        android:gravity="fill_vertical|center"
        android:textSize="24.0sp"
        android:textStyle="bold"
        android:scrollHorizontally="true"
        android:maxLines="1"
        android:editable="true" />

    <LinearLayout
        android:id="@+id/Row1"
        android:background="@android:color/black"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/EditTextPhoneNumber">
      <!--  Buttons 1 2 3 -->
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button1"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_1_no_vm" />

      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button2"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_2" />

      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button3"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_3" />

    </LinearLayout>

    <!-- Buttons 4 5 6 -->
    <LinearLayout
        android:id="@+id/Row2"
        android:background="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Row1">

      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button4"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_4" />

      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button5"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_5" />

      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button6"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_6" />

    </LinearLayout>
    <!-- Buttons 7 8 9 -->
    <LinearLayout
        android:id="@+id/Row3"
        android:background="@android:color/black"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Row2">
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button7"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_7" />
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button8"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_8" />
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button9"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_9" />
    </LinearLayout>
    <!-- Buttons * 0 # -->
    <LinearLayout
        android:id="@+id/Row4"
        android:background="@android:color/black"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Row3">
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/ButtonStar"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_star" />
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/Button0"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_0" />
      <ImageButton
          android:layout_weight="1"
          android:id="@+id/ButtonHash"
          android:onClick="onClick"
          style="@style/DialerButton"
          android:src="@drawable/dial_num_pound" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/Row5"
        android:background="@android:color/black"
        android:layout_height="48.0dip"
        android:layout_width="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/Row4">
      <ImageButton
          android:id="@+id/ButtonContract"
          android:onClick="onClick"
          android:background="@drawable/bg_button"
          android:src="@drawable/button_contract"
          android:layout_width="0dip"
          android:layout_height="fill_parent"
          android:layout_weight="1" />
      <ImageButton
          android:id="@+id/ButtonCall"
          android:onClick="onClick"
          android:src="@drawable/button_call"
          android:background="@drawable/bg_button"
          android:layout_width="0dip"
          android:layout_height="fill_parent"
          android:layout_weight="2" />
      <ImageButton
          android:id="@+id/ButtonDelete"
          android:onClick="onClick"
          android:background="@drawable/bg_button"
          android:src="@drawable/button_backspace"
          android:layout_width="0dip"
          android:layout_height="fill_parent"
          android:layout_weight="1" />
    </LinearLayout>
  </RelativeLayout>