2013-11-14 3 views
0

Я пытаюсь добавить пользовательский макет в ActionBar с использованием ActionBarSherlock библиотеку. Я считаю, что, хотя кажется, что ошибки нет, макет не отображается.Добавление пользовательского макета в ActionBarSherlock терпит неудачу

 View customView=LayoutInflater.from(this).inflate(R.layout.layout_actionbar_top,null); 
    ImageButton ab_camera=(ImageButton) customView.findViewById(R.id.ab_camera); 
    ImageButton ab_gallery=(ImageButton)customView.findViewById(R.id.ab_gallery); 
    ab_camera.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent(getBaseContext(),CameraActivity.class)); 
     }}); 

    ab_gallery.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent intent=new Intent(); 
      intent.setAction(Intent.ACTION_GET_CONTENT); 
      intent.setType("image/*"); 
      intent.addCategory(Intent.CATEGORY_OPENABLE); 
      startActivityForResult(intent, IMAGE_REQUEST_CODE); 

     }}); 
    LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.RIGHT | Gravity.CENTER_VERTICAL); 
    getSupportActionBar().setCustomView(customView,params); 

Активность вместо этого загружается без пользовательского макета в ActionBar.

Это Нестандартная планировка, 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"> 

<ImageButton android:id="@+id/ab_camera" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@android:drawable/ic_menu_camera"/> 

<ImageButton android:id="@+id/ab_gallery" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@android:drawable/ic_menu_gallery" 
      /> 
</LinearLayout> 

ответ

0

мне не удалось установить флаг, позволяющий ActionBarSherlock отображать мой customView к истине.

getSupportActionBar().setDisplayShowCustomEnabled(true); 
Смежные вопросы