johannilsson / android-actionbar

DEPRECATED Android Action Bar Implementation
1.31k stars 564 forks source link

Layout adjustments #6

Closed ohhorob closed 13 years ago

ohhorob commented 13 years ago

I've needed to make changes for my own project, and I've tried to re-factor those requirements so they will be usable by others.

The goal was to allow the Action Bar items to use bar-size (full height) buttons.

Additionally I updated the example project to show that my changes are compatible with the standard use.

I'm not sure what your policy is with .gitignore? I added one that prevents cruft showing up in git status after running $ android update project --path <proj-path> --subprojects

Feel free to suggest changes for me to make to ensure a clean pull, or make those changes yourself if you feel inclined.

If you're not comfortable pulling these changes in, I'll just keep pulling any changes that you make to keep my usage in kind.

Thanks,

Rob.

johannilsson commented 13 years ago

Thank you.

This looks good, but currently it breaks the height of the action bar in another project of mine that's using the action bar. I had to apply the following patch to your suggestion to fix the height problems I noticed in that app;

diff --git a/actionbar/res/layout/actionbar.xml b/actionbar/res/layout/actionbar.xml
index 151a963..d3c8f01 100644
--- a/actionbar/res/layout/actionbar.xml
+++ b/actionbar/res/layout/actionbar.xml
@@ -16,14 +16,14 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/screen"
     android:layout_width="fill_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="@dimen/actionbar_height"
     android:orientation="horizontal"
     android:background="@drawable/actionbar_background"
     >
     <RelativeLayout
         android:id="@+id/actionbar_home"
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:layout_height="@dimen/actionbar_height"
         android:orientation="horizontal"
         android:layout_alignParentLeft="true"
         android:layout_centerVertical="true"
@@ -32,7 +32,7 @@
         <ImageView
             android:id="@+id/actionbar_home_logo"
             android:layout_width="wrap_content"
-            android:layout_height="45dip"
+            android:layout_height="@dimen/actionbar_height"
             android:background="@drawable/actionbar_btn"
             android:padding="0dip"
             android:visibility="gone"
@@ -40,7 +40,7 @@
         <RelativeLayout
             android:id="@+id/actionbar_home_bg"
             android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_height="@dimen/actionbar_height"
             android:orientation="horizontal"
             android:layout_alignParentLeft="true"
             android:layout_centerVertical="true"
@@ -50,16 +50,15 @@
             <!-- TODO: Make configurable. -->
             <ImageButton
                 android:id="@+id/actionbar_home_btn"
-                style="@style/ActionBarItem"
+                style="@style/ActionBarHomeItem"
                 android:background="@drawable/actionbar_btn"
-                android:layout_marginRight="1px"
                 />
         </RelativeLayout>

         <LinearLayout
            android:id="@+id/actionbar_actions"
            android:layout_width="wrap_content"
-           android:layout_height="wrap_content"
+           android:layout_height="@dimen/actionbar_height"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
             android:layout_margin="0dp"
diff --git a/actionbar/res/values/styles.xml b/actionbar/res/values/styles.xml
index 6c0d6e1..7ec7c1e 100644
--- a/actionbar/res/values/styles.xml
+++ b/actionbar/res/values/styles.xml
@@ -21,9 +21,13 @@
         <item name="android:background">@drawable/actionbar_background</item>
     </style>
     <style name="ActionBarItem">
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_width">@dimen/actionbar_item_width</item>
+        <item name="android:layout_height">@dimen/actionbar_height</item>
         <item name="android:padding">5dp</item>
         <item name="android:layout_marginLeft">1px</item>
     </style>
+    <style name="ActionBarHomeItem" parent="ActionBarItem">
+        <item name="android:layout_marginRight">1px</item>
+        <item name="android:layout_marginLeft">0px</item>
+    </style>
 </resources>

Not necessary to fix the height problem, but I've also added a new style ActionBarHomeItem for the actionbar_home_btn, this allows it to be customized independent from the ActionBarItem that might not always look the same.

Does this break your intentions with the original patch?

ohhorob commented 13 years ago

That looks fine. I'd be happy with those changes.

johannilsson commented 13 years ago

Great, will apply it later on tonight then. But I guess there must be a more elegant way to have the items inherit the action bar height. I guess it's the separator that breaks it all, will look into that later on.

Thanks again for your contribution.

johannilsson commented 13 years ago

Merged and pushed. I hope this plays well with your app. If you have to do further changes just send another pull request.