14

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

mmo
  • 3,897
  • 11
  • 42
  • 63
  • i may be mistaken, but i believe you are supposed to use "14px" instead of "14dp" for the android:textSize element – mtmurdock Sep 12 '10 at 19:56
  • @mtmurdock, Units can be specified in px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters). (Source: http://developer.android.com/reference/android/widget/TextView.html#attr_android:textSize) – Brian Sep 12 '10 at 22:47
  • "px" should be avoided at all costs, for compatibility with varying DPI devices. – warbi Oct 22 '13 at 12:03

5 Answers5

23

I think you should use sp instead of dp.

android:textSize="20sp"
Yogesh Umesh Vaity
  • 41,009
  • 21
  • 145
  • 105
Than Zaw
  • 261
  • 3
  • 5
  • wrong, dp i fixed units, sp is affected by user's settings - under accessibility (for people with vision problems) – Wops Jan 23 '17 at 07:26
7

Try 'dip' instead of 'dp' for textSize property. I dunno why, but sometimes using 'dp' takes no effect, even though documentation says that those two are equal. So I always use 'dip'.

Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
  • 1
    how come TEXT SIZE is measured in "dp" or "dip", as far as I believe it should be specified with "sp" – candy Jan 07 '14 at 11:59
2

Try the following in your main_Activity.java

final Button btpls=(Button) findViewById(R.id.btpls);

btpls.setOnClickListener(new OnClickListener(){
    public void onClick(View t){
        float i=textfield.getTextSize();
       textfield.setTextSize(i+1) ; 
    }
});

final Button btmins=(Button) findViewById(R.id.btmins);

btmins.setOnClickListener(new OnClickListener(){
    public void onClick(View t){
        float n=textfield.getTextSize();
        textfield.setTextSize(n-1); 
    }
});
rakhi4110
  • 9,253
  • 2
  • 30
  • 49
samer
  • 71
  • 8
0

Stupid system won't let me downvote or comment.

sp is also density-independent. The difference between sp and dp is that sp is scaled according to the user's font size preferences. This means that all fonts and user interface elements that need to scale with the size of the font, should be done in sp units. Only items that should not scale with the font size should be done in dp units.

Evan Langlois
  • 4,050
  • 2
  • 20
  • 18
0

In your styles.xml

<style name="HintTextSize" parent="TextAppearance.Design.Hint">
        <item name="android:textSize">16sp</item>
        <item name="android:paddingLeft">16sp</item>
    </style> 

<android.support.design.widget.TextInputLayout
    android:id="@+id/trailer_one_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    **app:hintTextAppearance="@style/TextLabel"
    android:layout_marginTop="10dp">

        <EditText
            android:id="@+id/edit_text_trailer_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:hint="@string/trailer_one"
            android:inputType="text"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/DrivingDarkGrey"/>
    </android.support.design.widget.TextInputLayout>
Manikandan K
  • 911
  • 9
  • 21