Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increase ListFragment inbuilt empty text view size

I m using listfragment in my app. When the data fails to load I call setEmptyText with the failure message. This works fine on 4 inch phones but on 7 and 10 inch phones the size of the empty textview is very small and hard to read.

4 inch empty text view

enter image description here

7 inch empty text view

enter image description here

How can I increase the size of empty text view?

like image 354
Vihaan Verma Avatar asked Jul 04 '14 13:07

Vihaan Verma


1 Answers

You can provide your own TextView to be used as the "empty text", it just needs to have android:id="@id/android:empty" and the ListFragment will use it instead of the standard one.

You could then customize the style of this TextView however you like (either statically in the xml layout):

 <TextView android:id="@id/android:empty"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:textSize="... />

or by calling findViewById() in onCreateView():

TextView emptyTextView = (TextView)view.findViewById(android.R.id.empty);
emptyTextView.setTextSize(...);

A (very good) alternative, as @Delblanco commented, is to call getListView().getEmptyView(). It will return either the TextView with id android.R.id.empty (if supplied in the layout), or the standard TextView that is used otherwise.

like image 123
matiash Avatar answered Oct 11 '22 17:10

matiash