2013-02-13 124 views
-1

我的要求是當edittext點擊選項「粗體」,「斜體」,「下劃線」,「字體」和「顏色」時打開菜單。點擊編輯文字打開菜單

請有人可以幫我這個..

+0

閱讀上下文菜單。 – meh 2013-02-13 13:34:10

+0

http://stackoverflow.com/questions/4402820/oncreatecontextmenu-for-edittext-doesnt-work-on-real-device – baboo 2013-02-13 13:35:18

回答

1

以下是我結束瞭解決這個:

EditText menuEdit = (EditText) activity.findViewById(R.id.menuImageView); 
    menuEdit.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      activity.openOptionsMenu(); //This is the key method! 
     } 
    }); 

public boolean onCreateOptionsMenu(Menu menu) { 
    com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); 
    inflater.inflate(R.menu.main_menu, menu); 
    return true;  
} 

public boolean onMenuItemClick(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.demographics: 

      return true; 
     case R.id.settings: 
      Log.v("v", "settings clicked"); 
      return true; 
     default: 
      return false; 
    } 
}