2014-03-25 33 views

回答

0

enter image description here

使用此在您的活動

ActionBar actionBar = getActionBar(); 
    actionBar.setDisplayShowTitleEnabled(false); 

    LayoutParams lp = new LayoutParams(
      android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 
      android.view.ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT 
        | Gravity.CENTER_VERTICAL); 
    View customNav = LayoutInflater.from(this).inflate(R.layout.img, null); 
    EditText et = (EditText) customNav.findViewById(R.id.et); 
    temppaths = new ArrayList<String>(); 
    Button iv = (Button) customNav.findViewById(R.id.iv); 
    iv.setClickable(true); 
    iv.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 

     } 
    }); 
    actionBar.setCustomView(customNav, lp); 
    actionBar.setDisplayShowCustomEnabled(true); 

和xmlLayout命名img.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:orientation="horizontal" 
android:layout_height="wrap_content" 
android:gravity="right" > 
<EditText android:id="@+id/et" 
    android:layout_width="250dp" 
    android:layout_height="match_parent" 
    android:layout_marginRight="20dp" 
    android:gravity="center" 
    android:layout_gravity="right" 
    android:hint="[email protected], 1800xxxxx" 
    android:background="#FF8000" /> 
<Button 
    android:id="@+id/iv" 
    android:layout_gravity="right" 
    android:layout_width="150dp" 
    android:layout_height="match_parent" 
    android:layout_marginRight="20dp" 
    android:text="Search" 
    android:background="#FF8000" /> 
</LinearLayout > 
+0

我希望顯示在首選項Activity.It必須在onCreateOption(),onOptionItemSelected()內完成。 –

+0

我不明白你試圖做 – raj

+0

Mr.raj你調用menuItem.Clearly理解的問題,我需要做的菜單項上的其他行動,我如何實現。我需要註銷,當我退出的方式人。 –

0

OKK然後

在你的活動添加這些方法

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); 

    menu.add(0, 0, 0, "LogOut").setShortcut('0', 'o') 
      .setIcon(android.R.drawable.ic_menu_edit); 
    menu.add(0, 1, 0, "Save").setShortcut('1', 's') 
      .setIcon(android.R.drawable.ic_menu_save); 

    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
    case 0: 
     Toast.makeText(getApplicationContext(), "Log out clicked", 0).show(); 
     // save(); 
     // showNewOrOpenDialog(); 
     break; 
    case 1: 
     Toast.makeText(getApplicationContext(), "Save", 0).show(); 
     // save(); 
     break; 
    } 
    return false; 
} 
相關問題