2014-11-09 3 views
0

어떻게하면 작업 표시 줄에 메인 메뉴를 만들 수 있으며 하드웨어 버튼을 클릭 할 때 열리는 "옵션"메뉴를 만들 수 있습니까?메뉴 및 옵션 메뉴 함께하기

Whatsapp와 유사합니다.

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.calendar, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_legend) { 
     // Open dialog 
    } else if(id == R.id.action_settings) { 
     startActivity(new Intent(this, SettingsActivity.class)); 
    } else if(id == R.id.action_add) { 
     startActivity(new Intent(this, AddActivity.class)); 
    } 
    return super.onOptionsItemSelected(item); 
} 

@Override 
public boolean onKeyDown(int keycode, KeyEvent e) { 
    switch(keycode) { 
     case KeyEvent.KEYCODE_MENU: 
      // Here open the options menu 
      return true; 
    } 

    return super.onKeyDown(keycode, e); 
} 
:이 아바타, 이름과 아이콘이있는 액션 바는 그리고 당신이 누르면 "메뉴"버튼을, 그것과 다른 메뉴가 나타납니다이 내 실제 코드 등

을 "연락처, 미디어, 검색"

+0

하드 메뉴 키가있는 구형 장치를 보면 해당 키를 누르면 메뉴가 활성화/비활성화됩니다. 특별한 일은 할 필요가 없습니다. –

+0

하지만이 버튼은 액션 바에있는 메인 메뉴이며 하드웨어 버튼 클릭으로 다른 것을 보여주고 싶습니다. 나는 두 가지 메뉴를 부 풀릴 수 있다고 생각하지 않는다. – Grork

답변

0

1 액션 오버 플로우

Action overflow

developer.android.com에 따르면, 오버 플로우 아이콘은 어떤 메뉴 하드웨어 키가없는 전화에 나타납니다. 메뉴 키가있는 폰은 사용자가 키를 누를 때 액션 오버플로를 표시합니다. 위하여 구현

2- WhatsApp에 메뉴 또는 WhatsApp 같이 구현한다.

Attachment

Menu

2의 (a) - 응용 프로그램 : showAsAction

당신은 멋진 일을 할 필요가 없습니다. 단지 app:showAsAction 속성을 사용하십시오.

첨부 파일에 대해 app : showAsAction = "always"을 설정하면 항상 표시됩니다.

다른 옵션의 경우 app : showAsAction = "never | withText"을 사용하면 하드웨어/오버플로 버튼을 눌렀을 때만 나타납니다.

다음은 menu_conversation.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<!-- Attachments --> 
<item 
    android:id="@id/menu_attachments" 
    android:icon="@drawable/ic_action_attach" 
    android:orderInCategory="1" 
    app:showAsAction="always" 
    android:title="@string/menu_attachments" /> 

<!-- Contact info --> 
<item 
    android:id="@id/menu_view_contact" 
    android:orderInCategory="2" 
    app:showAsAction="never|withText" 
    android:title="@string/menu_contact_info"/> 

<!-- Call --> 
<item 
    android:id="@id/menu_call" 
    android:orderInCategory="3" 
    app:showAsAction="never|withText" 
    android:title="@string/menu_call"/> 

<!-- Set Timer --> 
<item 
    android:id="@id/menu_timer" 
    android:orderInCategory="4" 
    app:showAsAction="never|withText" 
    android:title="@string/menu_set_timer"/> 

<!-- Wallpaper --> 
<item 
    android:id="@id/menu_wallpaper" 
    android:orderInCategory="5" 
    app:showAsAction="never|withText" 
    android:title="@string/menu_wallpaper"/> 

<!-- More --> 
<item 
    android:id="@id/menu_more" 
    android:orderInCategory="6" 
    app:showAsAction="never|withText" 
    android:title="@string/menu_more"/> 
</menu> 

의 연결 코드 * -BONUS

첨부 파일 메뉴처럼 또는 WhatsApp을 구현하기위한 사용 WhatsApp-Conversation-Menu. WhatsApp attachment menu