我无法删除操作栏下方的阴影,我已经尝试使用android:windowContentOverlay @null但它没有改变任何东西,我使用的是API 21,如何删除那影子?
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="Transparent" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>
</style>
<style name="MyActionBar"
parent="AppTheme">
<item name="android:actionBarStyle">@style/Transparent</item>
<item name="actionBarStyle">@style/Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
我也试过了:
getSupportActionBar().setElevation(0);
NavigationDrawer:
public class NavigationMain extends ActionBarActivity implements Animation.AnimationListener {
public int lastPosition = 0;
private ListView listDrawer;
private int counterItemDownloads;
private DrawerLayout layoutDrawer;
private LinearLayout linearDrawer;
private RelativeLayout userDrawer;
private ActionBarDrawerToggleCompat drawerToggle;
private final int GALLERY_ACTIVITY_CODE = 200;
private final int RESULT_CROP = 400;
private NavigationAdapter navigationAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation_main);
getSupportActionBar().setCustomView(R.layout.custombar);
getSupportActionBar().setDisplayOptions(DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_HOME_AS_UP);
getSupportActionBar().setElevation(0);
listDrawer = (ListView) findViewById(R.id.listDrawer);
linearDrawer = (LinearLayout) findViewById(R.id.linearDrawer);
layoutDrawer = (DrawerLayout) findViewById(R.id.layoutDrawer);
userDrawer = (RelativeLayout) findViewById(R.id.userDrawer);
userDrawer.setOnClickListener(userOnClick);
if (listDrawer != null) {
navigationAdapter = NavigationList.getNavigationAdapter(this);
}
listDrawer.setAdapter(navigationAdapter);
listDrawer.setOnItemClickListener(new DrawerItemClickListener());
drawerToggle = new ActionBarDrawerToggleCompat(this, layoutDrawer);
layoutDrawer.setDrawerListener(drawerToggle);
if (savedInstanceState != null) {
setLastPosition(savedInstanceState.getInt(Constant.LAST_POSITION));
navigationAdapter.resetarCheck();
navigationAdapter.setChecked(lastPosition, true);
} else {
setLastPosition(lastPosition);
setFragmentList(lastPosition);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(Constant.LAST_POSITION, lastPosition);
}
private static final int REFRESH = 1;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case Menus.HOME:
if (layoutDrawer.isDrawerOpen(linearDrawer)) {
layoutDrawer.closeDrawer(linearDrawer);
} else {
layoutDrawer.openDrawer(linearDrawer);
}
case REFRESH:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
public void setTitleActionBar(CharSequence informacao) {
getSupportActionBar().setTitle(informacao);
}
public void setSubtitleActionBar(CharSequence informacao) {
getSupportActionBar().setSubtitle(informacao);
}
public void setIconActionBar(int icon) {
getSupportActionBar().setIcon(icon);
}
public void setLastPosition(int posicao) {
this.lastPosition = posicao;
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
private class ActionBarDrawerToggleCompat extends ActionBarDrawerToggle {
public ActionBarDrawerToggleCompat(Activity mActivity, DrawerLayout mDrawerLayout) {
super(
mActivity,
mDrawerLayout,
R.drawable.ic_menu,
R.string.drawer_open,
R.string.drawer_close);
}
@Override
public void onDrawerClosed(View view) {
supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
navigationAdapter.notifyDataSetChanged();
supportInvalidateOptionsMenu();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int posicao, long id) {
layoutDrawer.closeDrawer(linearDrawer);
setLastPosition(posicao);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
setFragmentList(lastPosition);
}
}, 350);
}
}
private OnClickListener userOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
layoutDrawer.closeDrawer(linearDrawer);
}
};
public void setFragmentList(int posicao) {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.Fragment fragment = new InstituicoesActivity();
switch (posicao) {
case 0:
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commitAllowingStateLoss();
break;
// case 1:
// fragment = new MensagensFragment();
// break;
// case 2:
// fragment = new EscolasFragment();
// break;
// case 3:
// fragment = new AutorizadasFragment();
// break;
// case 4:
// fragment = new CadastroFragment();
// break;
default:
break;
}
// update selected item and title, then close the drawer
navigationAdapter.resetarCheck();
navigationAdapter.setChecked(posicao, true);
layoutDrawer.closeDrawer(linearDrawer);
}
public int getCounterItemDownloads() {
return counterItemDownloads;
}
public void setCounterItemDownloads(int value) {
this.counterItemDownloads = value;
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
答案 0 :(得分:1)
之前我遇到过这个问题而process.kill()
没有解决我的问题。
但android:windowContentOverlay = @null
方法有效。只需将其用于setElevation(0)
或Toolbar
。
例如:
AppBarLayout
答案 1 :(得分:1)
接受的答案对我不起作用。
要删除AppBarLayout中的阴影,请使用
AppBarLayout xml或中的 app:elevation="0"
在java中使用mAppBarLayout.setTargetElevation(0)
。
我试过,它对我有用。