开发者

Change font size of gridview items (Android)

开发者 https://www.devze.com 2023-03-21 12:27 出处:网络
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.

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开发者_JS百科);
        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.


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.


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));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号