1

I'm trying to make a custom keyboard for an android app so I'm trying to make the text on the buttons as readable as possible. I want the text to be big on the button, but setting the textSize attribute doesn't work, as it makes the text not fit. Is there a way to make the text take up a bigger part of the button, so that it can be large while still fitting on the button? Description of problem here

I tried to change the text size but it constrains the bounds of where the text can go.

Here is the xml file I'm trying to achieve this in: (accessLettersButton is the id of the button that I'm trying to do this for.)

<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"
    tools:context="naturaldeductionapp.DeductionFragment">

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.5">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/deductionLineRecyclerView"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent" />
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </HorizontalScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/accessLettersButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_marginVertical="0dp"
                android:layout_weight="1"
                android:backgroundTint="#FF6565"
                android:includeFontPadding="false"
                android:text="ABC"
                android:textColor="#000000"
                android:textSize="16sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/leftBracketButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_marginVertical="0dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="("
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/rightBracketButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_marginVertical="0dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text=")"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/clearButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_marginVertical="0dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="C"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/backspaceButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#AAAAAA"
                android:text="⌫"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/universalButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="∀"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/negationButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="¬"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/conjunctionButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="∧"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/exitEnterButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="e⏎"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/suppositionButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#AAAAAA"
                android:text="p."
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/existentialButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="∃"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/contradictionButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="⊥"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/disjunctionButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="∨"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/arrowUpButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="↑"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/enterButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#AAAAAA"
                android:text="⏎"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/conditionalButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="→"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/biconditionalButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="↔"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/arrowLeftButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="←"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/arrowDownButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#ABABAB"
                android:text="↓"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />

            <Button
                android:id="@+id/arrowRightButton"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="1dp"
                android:layout_weight="1"
                android:backgroundTint="#AAAAAA"
                android:text="→"
                android:textColor="#000000"
                android:textSize="24sp"
                app:cornerRadius="5dp" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

1 Answer 1

0

It will be easier for us if you can share the code you are trying, but I tried creating the button with bigger texts as you want, and it looks quite good.

I have used ConstraintLayout as the parent layout.

<Button
    android:layout_width="120dp"
    android:layout_height="64dp"
    android:text="ABC"
    android:textColor="@color/black"
    android:textSize="28sp" />

This is what you want?

Share your code so that I can take a look what are you trying to do.

1
  • I edited the post to include the xml in which I'm trying to do this. I'm using a different layout, so I assume that that is the reason why your solution doesn't work for me. Could you tell me how to achieve this effect within the code I have posted? Commented Aug 8 at 7:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.