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!

1
  • post code of actionbarview layout Commented Oct 3, 2013 at 10:58

5 Answers 5

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); 
Sign up to request clarification or add additional context in comments.

Comments

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> 

12 Comments

@EmelElias you are writing 700dp instead of 100dp in my code?
@EmelElias values and values-v11 for portrait and landscape mode?
both values and values-11 is for portrait .i used the 100dp suggested .
i changed to 200dp still no luck
@EmelElias i think mainly we used 2 different style xml one for portrait and one for landscape. so just create only one dimens and one style xml.
|
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> 

Comments

1

The provided solution didnt work for me until I changed

android:height 

to simply

height 

Because AppCompat is not part of the system.

Comments

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.