2014-09-11 65 views
2

我在應用程序中使用navigationDrawer側欄,我無法禁用透明。閱讀之後的任何話題在這個網站我不能禁用它或者設置阿爾法Android禁用navigationDrawer透明

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

什麼「透明」你要刪除? – 2014-09-11 09:19:52

+0

@PedroOliveira http://rupload.ir/upload/h9i061f3hqt01adl9022.png – 2014-09-11 09:27:37

+0

你想讓它變成全黑嗎? – 2014-09-11 09:31:52

回答

1

如果你的目的是爲了表明一個黑色的佈局,而不是透明度,你可以試試這個:

在您的NavigationDrawerFragment上搜索該行:

mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); 

和替換它

mDrawerLayout.setScrimColor(Color.BLACK);