특정 작업이 완료 될 때까지 내 탐색 창에서 두 번째 요소를 비활성화해야합니다. 여기에 내가 두 번째 요소 해제하는 방법입니다탐색 서랍 선택기가 작동하지 않음
nav_item_selector.xml (A DrawerLayout에 싸여)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/dark_green"
android:state_pressed="true" />
<item android:drawable="@android:color/transparent"
android:state_enabled="true" />
<item android:drawable="@android:color/darker_gray"
android:state_enabled="false" />
</selector>
nav_fragment.xml을
<ListView
android:id="@+id/left_drawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:cacheColorHint="#0000"
android:background="@drawable/gradient_radial_backround"
android:choiceMode="singleChoice"
android:divider="@color/green_light"
android:dividerHeight="1dp" />
nav_list_item.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/nav_item_selector"
android:orientation="horizontal"
android:padding="@dimen/standard_padding">
<ImageView
android:id="@+id/nav_list_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/nav_list_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:minHeight="@dimen/listPreferredItemHeightSmall"
android:paddingLeft="@dimen/activity_horizontal_small_margin"
android:text="List Item"
android:textSize="@dimen/text_nav_list_entry"
android:textColor="@color/dark_green" />
</LinearLayout>
활동 :
public class NavItemAdapter extends ArrayAdapter<String> {
LayoutInflater inflater;
private String[] listItems;
public NavItemAdapter(Context context, int textViewResourceId, String[] listItems) {
super(context, textViewResourceId, listItems);
this.listItems = listItems;
inflater = LayoutInflater.from(context);
}
@Override
public boolean isEnabled(int position)
{
if(position == 1)
return false;
else
return true;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = new NavItemView(getContext());
NavItemView navItemView = (NavItemView) convertView;
switch (position) {
case 0:
navItemView.setUpItem(R.drawable.ic_nav_1_checked, listItems[position], R.drawable.ic_nav_1);
break;
case 1:
navItemView.setUpItem(R.drawable.ic_nav_2_checked, listItems[position], R.drawable.ic_nav_2);
break;
case 2:
navItemView.setUpItem(R.drawable.ic_nav_3_checked, listItems[position], R.drawable.ic_nav_3);
break;
case 3:
navItemView.setUpItem(R.drawable.ic_nav_4_checked, listItems[position], R.drawable.ic_nav_4);
break;
case 4:
navItemView.setUpItem(R.drawable.ic_nav_5_checked, listItems[position], R.drawable.ic_nav_5);
break;
case 5:
navItemView.setUpItem(R.drawable.ic_nav_6_checked, listItems[position], R.drawable.ic_nav_6);
break;
}
return convertView;
}
}
class NavItemView extends LinearLayout implements Checkable {
private View v;
private ImageView iconView;
private TextView textView;
private Boolean checked = false;
private int mImageChecked;
private int mImage;
public NavItemView(Context context) {
super(context);
LayoutInflater inflater = LayoutInflater.from(context);
v = inflater.inflate(R.layout.list_item_navdrawer, this, true);
assert v != null;
iconView = (ImageView) v.findViewById(R.id.nav_list_icon);
textView = (TextView) v.findViewById(R.id.nav_list_text);
}
@Override
public boolean isChecked() {
return checked;
}
@Override
public void setChecked(boolean checked) {
this.checked = checked;
if (isChecked()) {
setBackgroundColor(getResources().getColor(R.color.transparent));
textView.setTextColor(getResources().getColor(R.color.light_pink));
iconView.setImageResource(mImageChecked);
} else {
//Reset to default
setBackgroundColor(getResources().getColor(R.color.transparent));
textView.setTextColor(getResources().getColor(R.color.green_lighter));
iconView.setImageResource(mImage);
}
}
@Override
public void toggle() {
checked = !checked;
}
private void setUpItem(int imageChecked, String title, int image) {
mImageChecked = imageChecked;
mImage = image;
textView.setText(title);
iconView.setImageResource(image);
}
}
항목이 사용 중지되었지만 선택 도구가 실행되지 않습니다 (동일한 색상으로 유지됨). 그뿐 아니라 그 항목의 칸막이는 더 나 빠지게됩니다! 여기서 무슨 일이 일어나고있는거야?