1

I am Trying to change the Height of ActionBar,the code i use is shown below

MainActivity:

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ActionBar actionBar = getSupportActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    View view = View.inflate(getApplicationContext(),
            R.layout.actionbarview, null);
    actionBar.setCustomView(view);
}

}

Values/styles.xml:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- general styles for the action bar -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="actionBarSize">700dp</item>
</style>

Values-v11/styles.xml

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<!-- general styles for the action bar -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
     <item name="android:actionBarSize">700dp</item>
</style>

actionbarview.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="match_parent"
android:layout_gravity="fill_horizontal"
android:background="#555333"
android:orientation="horizontal" >
<Button
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true" />
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="Title mswg" />
   <Button
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true" />
  </RelativeLayout>`

The problem is not the height does not change.My target sdk is 17.

Thanks in Advance!

Emel Elias
  • 572
  • 7
  • 18

5 Answers5

3

Looks similar to your code and it's strange... I have luck with this styles (values):

<style name="player" parent="@style/Theme.AppCompat">
    <item name="actionBarSize">90dp</item>
    <item name="actionBarStyle">@style/player.ActionBarStyle</item>
</style>

<style name="player.ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@drawable/ab_bgr</item>
</style>

values-v11

<style name="player" parent="@style/Theme.AppCompat">
    <item name="android:actionBarSize">90dp</item>
    <item name="android:actionBarStyle">@style/player.ActionBarStyle</item>
</style>

<style name="player.ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@drawable/ab_bgr</item>
</style>

ActionBarActivity

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
....

View customView = activity.getLayoutInflater().inflate(R.layout.player_ab,null);

    ActionBar actionBar = getSupportActionBar();
    //float scale = activity.getResources().getDisplayMetrics().density;

    actionBar.setCustomView(customView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));//(int) (90*scale + 0.5f)));
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
recoilme
  • 301
  • 3
  • 5
2

Try like this-

values/dimens.xml-

<resources>
     <dimen name="MyActionBar">100dp</dimen>
</resources>

Now you can use these dimensions like this-

<style [...]>
     <item name="android:actionBarSize">@dimen/MyActionBar</item>
</style> 

Another Easiest Way-

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarSize">100dp</item>
        <item name="actionBarSize">100dp</item>
</style> 
Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21
2

try this...

<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
   <item name="actionBarStyle">@style/actionBarHeight</item>
   <item name="android:actionBarStyle">@style/actionBarHeight</item>
</style>
<style name="actionBarHeight" parent="@style/Widget.AppCompat.ActionBar">
     <item name="android:height">60dp</item>
 </style>
Manmohan Pal
  • 1,577
  • 1
  • 12
  • 13
1

The provided solution didnt work for me until I changed

android:height

to simply

height

Because AppCompat is not part of the system.

Pavel M.
  • 374
  • 6
  • 7
0

on res/values/styles.xml add this:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="height">55dp</item>
</style>

and on res/values-v11/styles.xml and res/values-v14/styles.xml add this:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:height">55dp</item>
</style>
Medo Elkamaly
  • 2,508
  • 1
  • 20
  • 15