Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to change the textsize in an EditText field?

I want to display a table with some fields being editable - see this example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 android:paddingLeft="1dip"
 android:paddingRight="1dip"
 android:paddingBottom="1dip"
 android:background="#F00"
 >
 <ScrollView
  android:id="@+id/ScrollView01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:scrollbars="vertical"
  >
  <HorizontalScrollView
   android:id="@+id/HorizontalScrollView01"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:scrollbars="horizontal"
   >
   <TableLayout
    android:id="@+id/ItemPane"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#EEE"
   >
    <TableRow
     android:id="@+id/DataRow"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"    
     android:background="#888"
     android:layout_margin="0dp" 
     android:gravity="left"
     >
     <TextView
      android:id="@+id/NameField"
      android:text="Fieldname"
      android:background="#EEE"
      android:textSize="14dp"
      android:layout_margin="1dp" 
      android:layout_marginBottom="0dp" 
      android:paddingLeft="3dp"
      android:paddingRight="3dp"
     />
     <EditText
      android:id="@+id/DataField"
      android:text="some field"
      android:background="#EEE"
      android:textSize="14dp"
      android:layout_margin="1dp" 
      android:layout_marginBottom="0dp" 
      android:paddingLeft="3dp"
      android:paddingRight="3dp"
      android:singleLine="true"
     />
     <EditText
      android:id="@+id/DataField2"
      android:text="some longish field content..."
      android:background="#EEE"
      android:textSize="14dp"
      android:layout_margin="1dp" 
      android:layout_marginBottom="0dp" 
      android:paddingLeft="3dp"
      android:paddingRight="3dp"
      android:singleLine="true"
     />
    </TableRow>   
   </TableLayout>
  </HorizontalScrollView>
 </ScrollView>
</LinearLayout>

Why is the textSize attribute ignored in EditText-fields? How can I make the text in those fields smaller, so that ALL cells have the same font size? Why does Android not honor that attribute, even if explicitly set?

Michael

like image 209
mmo Avatar asked Sep 12 '10 19:09

mmo


People also ask

How will you set the size of a text in the edit text?

Go to File -> Settings, a new setting dialogue box will appear. Then go to Editor -> General. Now mark the checkbox Change font size with Ctrl + Mouse wheel and click on Apply button. Now to change your editor font size, you just have to press and hold Ctrl and rotate the Mouse wheel.

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.


1 Answers

I think you should use sp instead of dp.

android:textSize="20sp"
like image 131
Than Zaw Avatar answered Sep 20 '22 03:09

Than Zaw