我正在使用NavigationDrawerItemsAdapter监听器来显示滑块菜单中的选项,当选项少于显示半部分作为透明度时我想将白色背景显示为设备的高度。
public class BaseNavigationDrawerActivity extends BaseActivity implements
// for getting Left Navigation drawerImages
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_screen);
mContext = BaseNavigationDrawerActivity.this;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawersList = (ListView) findViewById(R.id.lv_left_drawer);
LayoutInflater inflater = this.getLayoutInflater();
// adding listview header
View header = inflater.inflate(R.layout.leftnav_headerview, null);
mDrawersList.addHeaderView(header);
mProfileView = (ImageView) header.findViewById(R.id.img_profile);
mProfileUserName = (TextView) header.findViewById(R.id.tv_username);
// set a custom shadow that overlays the main content when the drawer
// opens
ShowLogoutOption();
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_apphistory_menu, R.string.drawer_open,
R.string.drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
supportInvalidateOptionsMenu();
}
};
mNavigationDrawerAdapter = new NavigationDrawerItemsAdapter();
mDrawersList.setAdapter(mNavigationDrawerAdapter);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mProfileUserName.setEnabled(false);
mDrawersList.setOnItemClickListener(new DrawerItemClickListener());
mProfileView.setOnClickListener(this);
initActionBar("",false);
}
@Override
protected void onResume() {
super.onResume();
mNavigationDrawerAdapter.notifyDataSetChanged();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
private class DrawerItemClickListener implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long arg3) {
mDrawersList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
protected void replaceFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
}
/**
* This class used to update data to LeftNavigationDrawer
*
* @author nvanamala
*
*/
private class NavigationDrawerItemsAdapter extends BaseAdapter {
private ImageView mLeftNavigationImage;
private TextView mLeftNavigationText;
@Override
public int getCount() {
return mLeftNavigationDrawerItems.length > 0 ? mLeftNavigationDrawerItems.length
: 0;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.left_navigation_row,
null, false);
}
mLeftNavigationText = (TextView) convertView.findViewById(R.id.tv_left_nav_title);
mLeftNavigationImage = (ImageView) convertView.findViewById(R.id.img_left_nav);
mLeftNavigationText.setText(mLeftNavigationDrawerItems[position]);
// If the position is RewardPoints then add the points to reward point
if (mLeftNavigationText.getText().toString().trim().equalsIgnoreCase(mRewardPoints)) {
}
}
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String item = mLeftNavigationDrawerItems[position];
selectItem(item);
}
});
// mLeftNavMenuImages.recycle();
return convertView;
}
}
}
![enter image description here][1]
[1]: http://i.stack.imgur.com/iSXRR.png
答案 0 :(得分:1)
将此视图设置为findViewById(R.id.lv_left_drawer);
到xml中的FILL_PARENT或MATCH_PARENT。如果是一个linearlayout或者包含listview的relativelayout,那么设置主视图的背景颜色,将根视图设置为白色
@android:color/white
答案 1 :(得分:0)
DrawerLayout高度应该是填充或匹配父级,然后您可以以编程方式更改它
mDrawerLayout.setBackgroundColor(Color.WHITE);
希望这会有所帮助。