2014-12-13 6 views
0

Моя активность раздувает пользовательскую панель действий, чтобы получить переход градиента от непрозрачного черного к прозрачному при движении вверх.Пользовательская панель действий, не показывающая

EDIT: - Я изменил код, и теперь я получаю этот выход: - enter image description here

Мой код: -

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
       //action bar setting 
       //Getting Action Bar 
       ActionBar mActionBar= getActionBar(); 

       LayoutInflater minflate =(LayoutInflater) mActionBar.getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
       View mview = minflate.inflate(R.layout.subgrid_ab,null); 

       mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,ActionBar.DISPLAY_SHOW_CUSTOM|ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_TITLE); 
       mActionBar.setCustomView(mview, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); 

       TextView mtext =(TextView)mview.findViewById(R.id.subgridab_text); 
        mtext.setText("General"); 
       setContentView(R.layout.gridsub); 
} 

Это означает вид накачивают, но градиент эффект пока не отображается.

subgrid_ab.xml: -

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_ab" 
    > 

    <TextView 
     android:id="@+id/subgridab_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#ffffff" 
     android:layout_gravity="center" 
     android:text="dd" 
     android:textSize="24sp" 
     android:layout_centerInParent="true"/> 



</RelativeLayout> 

custom_ab.xml: -

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 



    <gradient 
     android:startColor="#FF000000" 
     android:endColor="#00000000" 
     android:angle="270" 
     /> 

</shape> 

Так что я делаю неправильно?

ответ

0
LayoutInflater minflate = LayoutInflater.from(this); 
View mview = minflate.inflate(R.layout.subgrid_ab,null); 
mActionBar.show(); 

И как ActionBar может знать о вашем мью-тесте?
Может быть, это может помочь:

getActionBar().setCustomView(mview); 

UPDATE

@Mohit нормально, попробуйте установить «@ + идентификатор» для относительного расположения и установить этот вид finded по идентификатору, как настраиваемое представление к бар действия деятельности

View mview = minflate.inflate(R.layout.subgrid_ab,null); 
View customView = mview.findViewById(R.id.yourRelativeLayoutId); 

mActionBar.setCustomView(customView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); 
+0

Все еще получая такой же выход, без изменений! – Mohit

Смежные вопросы