【问题标题】:Android Long pressed button Context menuAndroid 长按按钮上下文菜单
【发布时间】:2014-05-04 00:08:34
【问题描述】:

我有这个方法来启动通知。但现在我想将它绑定到长按按钮上下文菜单。我该怎么办?

public void ringtone(){
    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
     } catch (Exception e) {
         e.printStackTrace();

     }

【问题讨论】:

    标签: android button menu android-context ringtone


    【解决方案1】:
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.main, menu);//Menu Resource, Menu  
        return true;  
    }  
    @Override  
    public boolean onOptionsItemSelected(MenuItem item) {  
        switch (item.getItemId()) {  
            case R.id.List1:  
                 //List1 is a button in menu.xml
                 //it is the button you want to bind the method to
                 //call the function ringtone() fom here
                 ringtone();
              default:  
                return super.onOptionsItemSelected(item);  
        }  
    }  
    

    假设您已经制作了一个 ContextMenu 并在其中有一个带有

    的按钮
    android:id="@+id/List1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多