Что мне нужно: приведенный выше экран - мой выдвижной ящик. В этом расширяемом списке, если я нажал заголовок списка «DashBoard», я перенаправляюсь на активность панели. Здесь мне нужен текст «Dashboard», который будет синим цветом и другим текст должен быть черным. Когда я нажимаю «Дневное наблюдение», я хочу, чтобы текст «CRM» и «Today followups» был синим, а другие - черным. моей навигация ящик активность:Как изменить цвет текста выбранного элемента списка как заголовка, так и дочернего элемента в расширяемом списке?
public class BaseActivity extends AppCompatActivity {
protected DrawerLayout drawer;
ExpandableListView expListView;
ExpandableListAdapter listAdapter;
HashMap<String, List<String>> listDataChild,listDatachild2;
List<String> listDataHeader;
List<String> listDataHeader2;
public List<Integer> groupImages;
private NavigationView navigationView;
ViewStub viewStub;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testingnavi);
}
public void preparedrawer(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
navigationView = (NavigationView)findViewById(R.id.nav_view);
expListView = (ExpandableListView)findViewById(R.id.navList);
drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
setprofileimage();
prepareListData();
listAdapter = new ExpandableListAdapter(
this, listDataHeader,groupImages,listDataChild,drawer);
expListView.setAdapter(listAdapter);
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
return false;
}
});
expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// mDrawerLayout.closeDrawers();
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
View _lastColored;
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
drawer.closeDrawer(GravityCompat.START);
// TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
}
public void setviewstub(int layout_id){
viewStub=(ViewStub)findViewById(R.id.view_stub);
viewStub.setLayoutResource(layout_id);
viewStub.inflate();
}
public void setprofileimage(){
CircleImageView profilePictureView = (CircleImageView) navigationView.getHeaderView(0).findViewById(R.id.profile_image);
TextView Usernamenav=(TextView)navigationView.getHeaderView(0).findViewById(R.id.Usernamenav);
final Userloginsession userloginsession = new Userloginsession(getApplicationContext());
final HashMap<String, String> userlist = userloginsession. isGetuserDetails();
String first_namee=userlist.get(Userloginsession.IS_FIRST_NAME);
String last_namee=userlist.get(Userloginsession.IS_LAST_NAME);
Picasso.with(BaseActivity.this)
.load(Url.imgurl + userlist.get(Userloginsession.IS_IMAGE))
.fit().centerCrop()
.into(profilePictureView);
Usernamenav.setText(first_namee+" "+last_namee);
Log.i("imgurl",Url.imgurl + userlist.get(Userloginsession.IS_IMAGE));
}
private void prepareListData() {
groupImages= new ArrayList<Integer>();
groupImages.add(R.drawable.dashboard_icon);
groupImages.add(R.drawable.crm_icon);
groupImages.add(R.drawable.accouns_icon);
groupImages.add(R.drawable.settings_icon);
groupImages.add(R.drawable.logout_icon);
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Dashboard");
listDataHeader.add("CRM");
listDataHeader.add("Accounts");
listDataHeader.add("Settings");
listDataHeader.add("LogOut");
// Adding child data
List<String> Dashboard = new ArrayList<String>();
List<String> CRM = new ArrayList<String>();
CRM.add("Today Followup's");
CRM.add("Unhandled Followup(s)");
CRM.add("Today Appointments");
CRM.add("Unhandled Appointment(s)");
CRM.add("Cold Call(s)");
List<String> Accounts = new ArrayList<String>();
Accounts.add("Quotations");
Accounts.add("Orders");
Accounts.add("Payments");
List<String> Settings = new ArrayList<String>();
List<String> Logout = new ArrayList<String>();
listDataChild.put(listDataHeader.get(0), Dashboard);
listDataChild.put(listDataHeader.get(1), CRM); // Header, Child data
listDataChild.put(listDataHeader.get(2), Accounts);
listDataChild.put(listDataHeader.get(3), Settings);
listDataChild.put(listDataHeader.get(4), Logout);
}
public static void dointent(Context A1, Class A2){
Intent i = new Intent().setClass(A1, A2);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
A1.startActivity(i);
}
public static Typeface settypefacess(Context _context,String fonts){
Typeface roboto = Typeface.createFromAsset(_context.getAssets(),
fonts);
return roboto;
}
}
Моего адаптер: `
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private List<Integer> _group;
private DrawerLayout _drawer;
private static final int[] EMPTY_STATE_SET = {};
private static final int[] GROUP_EXPANDED_STATE_SET =
{android.R.attr.state_expanded};
private static final int[][] GROUP_STATE_SETS = {
EMPTY_STATE_SET, // 0
GROUP_EXPANDED_STATE_SET // 1
};
private HashMap<String, List<String>> _listDataChild;
ExpandableListView expandList;
public ExpandableListAdapter(Context context, List<String> listDataHeader, List<Integer> group,
HashMap<String, List<String>> listChildData, DrawerLayout drawer) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
this._group=group;
this._drawer=drawer;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
int childpositionaa= (int) getChildId(groupPosition,childPosition);
int gropuposi= (int) getGroupId(groupPosition);
Log.i("groupposi", String.valueOf(+groupPosition));
Log.i("groupposicc", String.valueOf(+childPosition));
Log.i("groupposiccee", String.valueOf(+childpositionaa));
int child3position=(int)getChildId(1,childPosition);
Log.i("groupposiccee33", String.valueOf(+child3position));
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
Log.i("childposition",""+childPosition);
Typeface roboto = Typeface.createFromAsset(_context.getAssets(),
"font/Roboto-Light.ttf");
AppCompatTextView txtListChild = (AppCompatTextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
_drawer.closeDrawer(GravityCompat.START);
switch (groupPosition) {
case 0:
break;
case 1:
switch (childPosition){
case 0:
BaseActivity.dointent(_context.getApplicationContext(),Handled_follow.class);
break;
case 1:
BaseActivity.dointent(_context.getApplicationContext(), Unhanded_follow.class);
break;
case 2:
BaseActivity.dointent(_context.getApplicationContext(), Navi_recyview.class);
break;
case 3:
BaseActivity.dointent(_context.getApplicationContext(), Unhandled_appoint.class);
break;
case 4:
BaseActivity.dointent(_context.getApplicationContext(), Cold_calls.class);
break;
}
break;
}
break;
}
return false;
}
});
AppCompatTextView txtchildcount= (AppCompatTextView) convertView
.findViewById(R.id.lblistnavcount);
txtListChild.setText(childText);
txtListChild.setTypeface(roboto);
txtchildcount.setText(myList.get(childpositionaa));
if(gropuposi==2){
if(childpositionaa==0){
txtchildcount.setText(myList.get(5));
}
else{
txtchildcount.setText(myList.get(4));
}
txtchildcount.setText(myList.get(childpositionaa+5));
}
else{
txtchildcount.setText(myList.get(childpositionaa));
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
int headerimg = _group.get(groupPosition);
Log.i("groupposigroupview", String.valueOf(+groupPosition));
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
AppCompatTextView lblListHeader = (AppCompatTextView) convertView
.findViewById(R.id.lblListHeader);
View ind = convertView.findViewById(R.id.indicicon);
if(ind != null) {
ImageView indicator = (ImageView)ind;
if(getChildrenCount(groupPosition) == 0) {
indicator.setVisibility(View.INVISIBLE);
} else {
indicator.setVisibility(View.VISIBLE);
if (isExpanded) {
lblListHeader.setTextColor(_context.getResources().getColor(R.color.colorPrimary));
indicator.setImageResource(R.drawable.ic_expand_less_black_18dp);
} else {
lblListHeader.setTextColor(_context.getResources().getColor(R.color.colorlisthead));
indicator.setImageResource(R.drawable.ic_expand_more_black_18dp);
}
}
}
Typeface roboto = Typeface.createFromAsset(_context.getAssets(),
"font/Roboto-Regular.ttf"); //use this.getAssets if you are calling from an Activity
lblListHeader.setTypeface(roboto);
lblListHeader.setText(headerTitle);
ImageView imgsListHeader = (ImageView) convertView
.findViewById(R.id.imagview);
imgsListHeader.setImageResource(headerimg);
lblListHeader.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
switch (groupPosition) {
case 0:
_drawer.closeDrawer(GravityCompat.START);
BaseActivity.dointent(_context.getApplicationContext(),Dashboard.class);
break;
case 1:
break;
case 2:
case 3:
_drawer.closeDrawer(GravityCompat.START);
break;
case 4:
_drawer.closeDrawer(GravityCompat.START);
break;
}
break;
}
return false;
}
});
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
`
@thank you w00ly ... см. Выше изображение, если я выбрал панель инструментов, я хочу, чтобы текст стал синим цветом, пока я не выберет другой список. Я выбираю холодные вызовы, тогда я хочу, чтобы CRM и текст холодных вызовов были синим цветом а другие - черные – lucky
Я полагаю, что все ваши действия простираются от BaseActivity. Ну, когда вы нажимаете на свой «Холодный звонок», вы начинаете намерение, не так ли? Здесь вы передаете выбранный элемент в качестве параметра (ваш класс). Вы также можете передать идентификатор, а при обновлении ящика используйте этот параметр, чтобы узнать, в каком разделе вы находитесь, и внесите соответствующие изменения в свой список. – w00ly