简体   繁体   中英

Change font size of gridview items (Android)

Below is code of my girdview. i need to change font size of the data. i aslo need to change default selection colour which is orange. please help i am new to android development.

       String[] tes={"AAA","BBB","CCC"};

       ArrayAdapter<String> aa = new ArrayAdapter<String>(
                this,
                android.R.layout.simple_list_item_1, 
                tes );
        gv.setAdapter(aa);
        gv.setOnItemClickListener(this);

You have to change the font size in the baseadapter class for the gridview.

Like this:

public View getView(int position, View convertView, ViewGroup parent) {
      TextView tv;
if (convertView == null) {
    tv = new TextView(context);
    tv.setLayoutParams(new GridView.LayoutParams(100, 80));
    tv.setTextSize(20);   //text size in gridview
}

The gridview just show whatever the

gridview.setAdapter(new MyAdapter (thi));" //MyAdapter class is where the getView method run

sets the setAdapter to contain.

a little bit too late but for others who are looking for it will work:

first you create this a simple_textview.xml(put it a name)

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:shadowColor="@color/grisActionBar"
/>

then in yout activity or fragment you set the adapter with the created textview.xml

gvMain = (GridView)v.findViewById(R.id.gridView);
gvMain.setAdapter(new ArrayAdapter<String
(getActivity(),R.layout.simple_textview,data));

You can try to achieve this by changing styles of your widgets. Take a look a this post to learn to apply styles and themes. Also you'll find description of all android styles and themes there. Hope this helps.

You can change it in the XML file, if you write android:textColor="#000000" where 000000 is the code of your color hexcode what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM