0

이미지의 화살표가 파란색에서 예를 들어 빨간색으로 표시된 것처럼 NavigationDrawer의 목록 항목 클릭 색상을 변경하는 방법을 알고 싶습니다. enter image description hereNavigationDrawer의 색상 변경 색상을 클릭하십시오.

내 두 번째 질문은 나는 액션 바 (상단 바)에서 MainActivity 활동에 사용자가 직접 것 클릭시 로고 (이미지)를 추가 할 것입니다, 아래 ActionBarActivity를 호출하는 활동 코드 .

public class MainActivity extends ActionBarActivity { 

    private String[] mOptionMenu; 
    private DrawerLayout mDrawerLayout; 
    private RelativeLayout mDrawerRelativeLayout; 
    private ListView mDrawerList; 
    private ActionBarDrawerToggle mDrawerToggle; 

    private CharSequence mTitleSection; 
    private CharSequence mTitleApp; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 



     mOptionMenu = new String[] { "Opción 1", "Opción 2", "Opción 3" }; 
     mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     mDrawerRelativeLayout = (RelativeLayout) 
     findViewById(R.id.left_drawer); 
     mDrawerList = (ListView) findViewById(R.id.list_view_drawer); 
     mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 
     mOptionMenu)); 

     mDrawerList.setOnItemClickListener(new OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
     int position, long id) { 

     Fragment fragment = null; 

     switch (position) { 
     case 0: 
     fragment = new FirstFragment(); 
     break; 
     case 1: 
     fragment = new SecondFragment(); 
     break; 
     case 2: 
     fragment = new ThirdFragment(); 
     break; 
     } 

     FragmentManager fragmentManager = getSupportFragmentManager(); 

     fragmentManager.beginTransaction() 
     .replace(R.id.content_frame, fragment).commit(); 

     mDrawerList.setItemChecked(position, true); 

     mTitleSection = mOptionMenu[position]; 
     getSupportActionBar().setTitle(mTitleSection); 

     mDrawerLayout.closeDrawer(mDrawerRelativeLayout); 
     } 
     }); 
     mDrawerList.setItemChecked(0, true); 
     mTitleSection = getTitle(); 
     mTitleApp = getTitle(); 

     mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
     R.drawable.ic_drawer, R.string.drawer_open, 
     R.string.drawer_close) { 

     public void onDrawerClosed(View view) { 
      getSupportActionBar().setTitle(mTitleSection); 
     ActivityCompat.invalidateOptionsMenu(MainActivity.this); 
     } 

     public void onDrawerOpened(View drawerView) { 
      getSupportActionBar().setTitle(mTitleSection); 
     ActivityCompat.invalidateOptionsMenu(MainActivity.this); 
     } 
     }; 

     mDrawerLayout.setDrawerListener(mDrawerToggle); 

     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     getSupportActionBar().setHomeButtonEnabled(true); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     getMenuInflater().inflate(R.menu.main_activity_actions, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 

     if (mDrawerToggle.onOptionsItemSelected(item)) { 
      return true; 
     } 

     switch (item.getItemId()) { 
     case R.id.action_settings: 
      Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show(); 
      ; 
      break; 
     default: 
      return super.onOptionsItemSelected(item); 
     } 

     return true; 
    } 

    @Override 
    protected void onPostCreate(Bundle savedInstanceState) { 
     super.onPostCreate(savedInstanceState); 
     mDrawerToggle.syncState(); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     mDrawerToggle.onConfigurationChanged(newConfig); 
    } 
} 

미리 감사드립니다.

+0

이 – Amy

+0

탐색 서랍을 할 수 = 탐색 창 – krossovochkin

답변

0

에 mDrawerList이 BG를 적용

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" android:drawable="@drawable/redbg"/> 
</selector> 

이. 이 API 레벨 이상 작동 11

원하는 색상 추가 navigation_list_background.xml 것은

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_activated="true" android:drawable="@color/green" /> 
    <item android:state_selected="true" android:drawable="@color/green" /> 
    <item android:state_pressed="true" android:drawable="@color/light_blue" /> 
    <item android:state_focused="true" android:drawable="@color/light_blue" /> 
    <item android:drawable="@color/blue" /> 

</selector> 

당신의 기본 스타일에 추가

<style name="AppTheme" parent="AppBaseTheme"> 
     <item name="android:activatedBackgroundIndicator">@drawable/navigation_list_background</item> 

    </style> 

이 당신의 품목 당신에게 인 (레이아웃에 배경을 추가 서랍에 표시)

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="?android:attr/activatedBackgroundIndicator" 
     android:orientation="horizontal" > 


     <TextView 
      android:id="@+id/title" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="8" 
      android:text="Option 1" /> 


    </LinearLayout> 

희망이 있습니다 !!

그리고 두 번째 질문입니다. 사용자 지정 작업 표시 줄을 사용할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <include layout="@layout/actionbar" /> 


    <--Your Layout--> 
</LinearLayout> 

customactionbar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/header_drawer" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/drawermenu" /> 

     <TextView 
      android:id="@+id/header_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="5dp" 
      android:text="TEST" 
      android:textStyle="bold" /> 
     <ImageView 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/button" /> 
    </LinearLayout> 

    <View 
     android:id="@+id/actionbarseperator" 
     android:layout_width="match_parent" 
     android:layout_height="3dp" 
     android:background="@color/blue" /> 

</LinearLayout> 

Yourlayout.xml가 온 클릭 버튼에 대한 추가의 setContent

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

전에 자바에서 이것을 추가합니다.

Button button=(Button)findViewById(R.id.button); 
    button.setOnClickListener(this); 

    public void onClick(View v) { 
    // TODO Auto-generated method stub 
    switch(v.getId()) 
    { 
    case R.id.button: 
    ActivityYouwantToOpen.onOpen(v); 
     break; 
     } 
     } 

그것의 긴 게시물 :! 그리기 XML을 사용하여 P

1

선택기를 사용하여 mDrawerList의 누른 상태의 색을 변경할 수 있습니다. 같은 우선, 입술에

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@android:color/holo_red_dark"/> 
</shape> 

다음 (listviewbg) 셀렉터 말을 생성/드로어 블/사진 redbg.xml 당신의 입술이 같은 (redbg 말) 붉은 색 고체 당김 모양을 만들/드로어 블/사진 listviewbg.xml 배경 표시에 대한 귀하의 첫 번째 질문에 XML

<ListView 
android:id="@+id/mDrawerList " 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:listSelector="@drawable/listviewbg" 
/> 
+0

내부 목록보기 두 번째 질문 :(PLZ 조금 설명을하지 않았다 죄송합니다. –