2014-12-13 115 views
0

我的活動正在充氣自定義操作欄,以便在上下移動時從不透明黑色變爲透明漸變。不顯示自定義操作欄

編輯: -我改變了我的代碼,現在我得到這樣的輸出: - 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如何知道你的mview?
也許它可以幫助:

getActionBar().setCustomView(mview); 

UPDATE

@Mohit OK,嘗試設置 「@ + id」 設爲相對佈局和設置這一觀點由ID瑤池作爲自定義視圖的動作欄

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 2014-12-14 05:06:03