我正在使用可扩展列表视图,我想更改我在其中使用的 textview 的样式。
我必须为扩展组视图和选定子视图的文本添加发光效果。
我的 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>
我的子视图的 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" />
我必须做的:-
我到目前为止所做的:-
我的可扩展列表视图适配器:-
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;
}
}
对此的任何线索将不胜感激!