2015-08-31 57 views
0

我的自定義操作欄視圖不是填充高度..它顯示爲圖片。自定義操作欄視圖 - 不填充高度

enter image description here

我使用AppCompatActivity(ActionBarActivity是不建議使用)。

ActionBar actionBar = pActivity.getSupportActionBar(); 
    actionBar.setDisplayShowHomeEnabled(false); 
    actionBar.setDisplayShowTitleEnabled(false); 
    LayoutInflater mInflater = LayoutInflater.from(pActivity); 

    View mCustomView = mInflater.inflate(R.layout.action_new, null); 

    TextView text_back = (TextView) mCustomView.findViewById(R.id.text_back); 
    text_back.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      pActivity.onBackPressed(); 
     } 
    }); 

    TextView text_reset = (TextView) mCustomView.findViewById(R.id.text_reset); 
    text_reset.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

     } 
    }); 
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    actionBar.setDisplayShowCustomEnabled(true); 
    actionBar.setCustomView(mCustomView); 
    Toolbar parent = (Toolbar) mCustomView.getParent(); 
    parent.setContentInsetsAbsolute(0, 0); 

以下是action_new佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:background="@color/bottom_green">  
    <TextView 
     android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="BACK" android:id="@+id/text_back" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:textColor="@color/text_in_green" android:padding="10dp" android:textSize="18dp" android:paddingLeft="15dp" 
     />  
    <TextView 
     android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RESET" android:id="@+id/text_reset" android:textColor="@color/text_in_green" android:textSize="18dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:padding="10dp" android:paddingRight="15dp" android:paddingEnd="15dp" 
     /> 
</RelativeLayout> 
+0

你檢查過'action_new'是否有任何'margin/padding'? – hrskrs

+0

請附上「action_new」的XML佈局。否則很難回答你的問題。 –

+0

請讓我看看佈局文件,以便我們清楚地瞭解它。 –

回答

0

快速修復,添加android:minHeight="?attr/actionBarSize"到你的RelativeLayout

爲了更好地處理和更自由的定製,你應該使用工具欄

+0

謝謝......它的工作... 我添加了一個工具欄...我認爲它也可以在沒有工具欄的情況下工作。 (Toolbar toolbar =(Toolbar)findViewById(R.id.toolbar); setSupportActionBar(toolbar);) – zacharia

0

您已添加一個10 dp的填充。

從兩個TextView中刪除android:padding="10dp"。它應該工作正常。

+0

我已經試過這個..不工作... – zacharia