skip to Main Content

There is such a picture As in the game 4 photos 1 word

enter image description here

I need to draw cells for letters. I do not remember the name of the style, it seems to me that Inner, when the cell is concave inward.

And the fact is that I did not work with Photoshop for drawing and use it with 9-Patch. In the vast Internet did not find (or not properly searched).

So the question is how to draw such a button or cell in Drawable?

2

Answers


  1. All you need is here.
    Very firstly you have to have this colors defined in your colors.xml in values folder.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <color name="darkBackground">#13161b</color>
        <color name="silveryBackground">#262d37</color>
    
    </resources>
    

    Then you need to create one file in drawable folder say layout_corners_dark.xml and copy this code in this file.

        <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/darkBackground"/>
        <stroke
            android:width="0dip"/>
        <corners android:radius="15dip"/>
        <padding
            android:bottom="0dip"
            android:left="0dip"
            android:right="0dip"
            android:top="0dip"/>
    </shape>
    

    Then you need to add button widgets in your activity_main.xml by applying layout_corners_dark.xml to it using android:background

    and your button xml will be like this

      <Button
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:text="K"
                android:textColor="@color/whiteTextColor"
                android:textSize="30sp"
                android:layout_margin="5dp"
                android:background="@drawable/layout_corners_dark"/>
    

    And apply silver background to your activity_main.xml using this line android:background="@color/silveryBackground" in your parent layout

    Finally your activity_main.xml will look like this.

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/silveryBackground"
        tools:context="com.example.user1.myapplication.MainActivity">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">
    
            <Button
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:text="K"
                android:textColor="@color/whiteTextColor"
                android:textSize="30sp"
                android:layout_margin="5dp"
                android:background="@drawable/layout_corners_dark"/>
    
            <Button
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:text="H"
                android:layout_margin="5dp"
                android:textColor="@color/whiteTextColor"
                android:textSize="30sp"
                    android:background="@drawable/layout_corners_dark"/>
            <Button
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:text="N"
                android:layout_margin="5dp"
                android:textColor="@color/whiteTextColor"
                android:textSize="30sp"
                android:background="@drawable/layout_corners_dark"/>
    
    </LinearLayout>
    </LinearLayout>
    

    And this is screenshot of this layout.
    See output here

    Login or Signup to reply.
  2. 1. Create a custom drawable file bg_rounded_corners.xml for rounded black box shape and put this drawable into your res/drawable folder.

    bg_rounded_corners.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- Bottom Shadow -->
        <item>
    
            <shape android:shape="rectangle" >
    
                <solid android:color="#2F2F3D" />
                <corners android:radius="4dp" />
    
            </shape>
        </item>
    
        <!-- Top Shadow -->
        <item android:bottom="2dp">
    
            <shape android:shape="rectangle" >
    
                <solid android:color="#000000" />
                <corners android:radius="4dp" />
    
            </shape>
        </item>
    
        <!-- Center Filled Color -->
        <item
            android:top="1dp"
            android:bottom="1.5dp">
    
            <shape android:shape="rectangle" >
    
                <gradient
                    android:startColor="#160A0F"
                    android:centerColor="#190B0F"
                    android:endColor="#1B0C13"
                    android:angle="270"/>
    
                <corners android:radius="4dp" />
    
            </shape>
        </item>
    </layer-list>
    

    2. Design your layout XML using LinearLayout with Horizontal orientation and put desired number of TextView inside this LinearLayout. Set custom drawable to each TextView using attribute android:background="@drawable/bg_rounded_corners".

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="16dp"
        android:background="#202531">
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_horizontal">
    
            <TextView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:gravity="center"
                android:paddingBottom="2dp"
                android:textSize="22sp"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:text="H"
                android:background="@drawable/bg_rounded_corners"/>
    
            <TextView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginLeft="2dp"
                android:paddingBottom="2dp"
                android:gravity="center"
                android:textSize="22sp"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:text="E"
                android:background="@drawable/bg_rounded_corners"/>
    
            <TextView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginLeft="2dp"
                android:paddingBottom="2dp"
                android:gravity="center"
                android:textSize="22sp"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:text="L"
                android:background="@drawable/bg_rounded_corners"/>
    
            <TextView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginLeft="2dp"
                android:paddingBottom="2dp"
                android:gravity="center"
                android:textSize="22sp"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:text="L"
                android:background="@drawable/bg_rounded_corners"/>
    
            <TextView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginLeft="2dp"
                android:paddingBottom="2dp"
                android:gravity="center"
                android:textSize="22sp"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:text="O"
                android:background="@drawable/bg_rounded_corners"/>
    
        </LinearLayout>
    </LinearLayout>
    

    OUTPUT:

    enter image description here

    FYI, I have used color #202531 as background color. For your case, you can use another color or use any image as background of root LinearLayout.

    Hope this will help~

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search