简体   繁体   English

如何在可扩展列表视图中更改TextView的样式?

[英]how to change the style of TextView in Expandable List View?

i am using expandable list view and i want to change the style of textview that i am using in it. 我正在使用可扩展列表视图,并且我想更改在其中使用的textview样式。
i have to add glowing effect to the text of both expanded group view and and selected child view. 我必须为扩展的组视图和选定的子视图的文本添加发光效果。

my xml code for GroupView :- 我的GroupView xml代码:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >


    <TextView
        android:id="@+id/groupelement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:textSize="21dp"
        android:gravity="left"
        />

    <ImageView
        android:id="@+id/ud_image"
        android:layout_width="wrap_content"
        android:layout_height="21dp"
        android:scaleType="centerInside"
        />
</LinearLayout>

my xml code for childview :- 我的childview的xml代码:-

   <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/submenuitem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:textSize="16dip"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp" />

what i have to do :- 我该怎么办:-

在此处输入图片说明

what i have done till now :- 我到目前为止所做的事情:-

在此处输入图片说明

my expandable list view Adapter :- 我的可扩展列表视图适配器:-

public class ExpandableMenuListAdapter extends BaseExpandableListAdapter {

    private LayoutInflater inflater;
    private ArrayList<ExpandableMenu> expandableMenu;
    private Context mContext;
    private Typeface tfBold;
    private Typeface tflight;
    private  Typeface tfregular;
    private TextView grpText;
    private TextView childText;
    private ImageView indicator;

    public ExpandableMenuListAdapter(ArrayList menus,Context context){
        expandableMenu=menus;
        mContext=context;
        tfBold = Typeface.createFromAsset(mContext.getAssets(), "fonts/Raleway-Bold.otf");
        tflight = Typeface.createFromAsset(mContext.getAssets(), "fonts/Raleway-Light.otf");
        tfregular = Typeface.createFromAsset(mContext.getAssets(), "fonts/Raleway-Regular.otf");
    }
    @Override
    public int getGroupCount() {
        return expandableMenu.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return expandableMenu.get(i).getSubMenu().size();
    }

    @Override
    public Object getGroup(int i) {
        return expandableMenu.get(i);
    }

    @Override
    public Object getChild(int i, int i2) {

        return expandableMenu.get(i).getSubMenu().get(i2);
    }

    @Override
    public long getGroupId(int i) {
        return 0;
    }

    @Override
    public long getChildId(int i, int i2) {
        return i2;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean isExpanded, View view, ViewGroup viewGroup) {

        inflater=(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            view = inflater.inflate(R.layout.groupview_with_child, null,false);
        }

        indicator=(ImageView)view.findViewById(R.id.ud_image);
        grpText=(TextView)view.findViewById(R.id.groupelement);
        String title = expandableMenu.get(i).getTitle();
        grpText.setText(title);
        grpText.setTypeface(tfregular);
        if ( getChildrenCount( i ) == 0 ) {
            indicator.setVisibility( View.INVISIBLE );
            view.setPadding(0, 0, 0, 20);
        } else {
            indicator.setVisibility(View.VISIBLE);
            indicator.setImageResource( isExpanded ? R.drawable.up : R.drawable.down );
            view.setPadding(0, 0, 0, 20);
            if(isExpanded) view.setPadding(0, 0, 0, 5);
        }

     /*   if(isExpanded){
            grpText.setTextAppearance(mContext,R.style.glow);
        }else{
            grpText.setTextAppearance(mContext,R.style.dim);
        }*/
        return view;
    }

    @Override
    public void onGroupExpanded(int groupPosition) {


        super.onGroupExpanded(groupPosition);
    }

    @Override
    public View getChildView(int i, int i2, boolean b, View view, ViewGroup viewGroup) {
        inflater=(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            view= inflater.inflate(R.layout.submenu, null,false);
        }

        if ((12 == expandableMenu.get(i).getSubMenu().size() - 1)){
            view.setPadding(0, 0, 0, 20);
        }
       childText = (TextView) view.findViewById(R.id.submenuitem);
        //"i" is the position of the parent/group in the list and
        //"i1" is the position of the child
        //textView.setText(mParent.get(i).getArrayChildren().get(i1));
        String subTitle= expandableMenu.get(i).getSubMenu().get(i2);

        childText.setText(subTitle);
        childText.setTypeface(tfBold);

        //view.setTag(holder);

        //return the entire view
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i2) {
        return true;
    }


}

any leads on this will be appreciated !! 任何线索对此将不胜感激!

Use android:shadowColor , android:shadowDx and android:shadowDy for the text view. 使用android:shadowColor,android:shadowDx和android:shadowDy进行文本视图。 Refer to the below link 请参考以下链接

How to add shadow to TextView on selection/focus 如何在选择/焦点上向TextView添加阴影

Cahnge your TextView As bwlow 将您的TextView更改为blow
Add style="@style/myshadowstyle" to it 向其中添加style =“ @ style / myshadowstyle”

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/submenuitem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:textSize="16dip"
    style="@style/myshadowstyle"
    android:paddingBottom="5dp"
    android:paddingLeft="10dp" />

Create styles.xml in your values folder as below 如下所示在您的values文件夹中创建styles.xml

  <?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="myshadowstyle">   
    <item name="android:shadowColor">#ff8800</item>
    <item name="android:shadowDx">-2</item>
    <item name="android:shadowDy">-2</item>
    <item name="android:shadowRadius">1</item>
    </style>
</resources>

Now here you can edit style as it suits to you 现在在这里您可以编辑适合您的样式

Try this 尝试这个

  1. if you want to change the text style of group list ...... 如果要更改组列表的文字样式...
    1. you can directly change ur headerlist.xml textview to CustomTextview like this <chifferobe.app.com.chifferobe.CustomTextView android:id="@+id/lblListHeader" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/iv_icon" android:textColor="@color/colorWhite" android:layout_marginLeft="@dimen/_15dp" android:textSize="@dimen/_15dp" /> 您可以像这样<chifferobe.app.com.chifferobe.CustomTextView android:id="@+id/lblListHeader" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/iv_icon" android:textColor="@color/colorWhite" android:layout_marginLeft="@dimen/_15dp" android:textSize="@dimen/_15dp" />将ur headerlist.xml文本视图直接更改为CustomTextview <chifferobe.app.com.chifferobe.CustomTextView android:id="@+id/lblListHeader" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/iv_icon" android:textColor="@color/colorWhite" android:layout_marginLeft="@dimen/_15dp" android:textSize="@dimen/_15dp" />
    2. if you want to change programmatically do this.... go to adapter class,then in your getGroupView method TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader); lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle); 如果要以编程方式进行更改,请执行此操作。...转到适配器类,然后在getGroupView方法TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader); lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle); TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader); lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle);
  2. and if you want in child list ...... 如果您想在子列表中...

    1.same as grouplist.xml do in your childlis.xml alse 1.与grouplist.xml在您的childlis.xml中相同

    1. if you want to change programmatically do this.... go to adapter class,then in your getChildView method TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem); lblListHeader.setTypeface(null, Typeface.BOLD); txtListChild.setText(childText); 如果要以编程方式进行更改,请执行此操作。...转到适配器类,然后在您的getChildView方法TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem); lblListHeader.setTypeface(null, Typeface.BOLD); txtListChild.setText(childText); TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem); lblListHeader.setTypeface(null, Typeface.BOLD); txtListChild.setText(childText);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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