我在应用程序中使用navigationDrawer侧边栏,我无法禁用透明。在阅读本网站的任何主题后,我无法禁用它或设置Alpha
activity_main:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ir.tsms.Activities.DashboardActivity" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<fragment
android:id="@+id/navigation_drawer"
android:name="ir.tsms.Fragments.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111111"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
fragment_main:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.tab.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
的活动:
public class DashboardActivity extends ActionBarActivity implements
NavigationDrawerFragment.NavigationDrawerCallbacks, ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
private Context context;
private NavigationDrawerFragment mNavigationDrawerFragment;
private CharSequence mTitle;
private int totalInboxSMS;
public ReceivedSMS dataReceived;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getBaseContext();
mNavigationDrawerFragment =
(NavigationDrawerFragment) getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer));
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@Override
public void onNavigationDrawerItemSelected(int position) {
if (mViewPager != null) {
mViewPager.setCurrentItem(position);
}
}
public void onSectionAttached(int number) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
private int mSectionNumber = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,false);
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((DashboardActivity) activity)
.onSectionAttached(getArguments().getInt(ARG_SECTION_NUMBER));
}
}
}
我正在测试这种方式:
mDrawerLayout.setScrimColor(Color.TRANSPARENT);
setDrawerShadow(Drawable shadowDrawable, int gravity)
setDrawerShadow(int resId, int gravity)
和
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111111"
但这种方式对我不起作用
答案 0 :(得分:1)
如果你的目标是显示黑色布局而不是透明度,你可以试试这个:
在NavigationDrawerFragment上搜索该行:
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
并将其替换为
mDrawerLayout.setScrimColor(Color.BLACK);