Reputation: 2056
I am developing android app and I used simple custom action bar. In my toolbar I added Logo pic using setLogo()
method but my logo size is too large so I got too much height of the action bar. In my android Studio emulator it display perfect with small size action bar but in my android mobile phone I got too large action bar.
Emulator running on Lolipop (API Level 21) and my android mobile working on Kitkat.
but in android emulator it display perfect
my code:
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(" " + currentChatContact.getName());
getSupportActionBar().setSubtitle(" last seen at 26/05/2015, 05:15 ");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setLogo(R.drawable.boy_thumbnail);
my toolbar code is:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/defaultPrimaryColor"> </android.support.v7.widget.Toolbar>
I am using AppCompat:
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/defaultPrimaryColor</item>
<item name="android:textColorPrimary">@color/textPrimaryColor</item>
<item name="android:textColor">@color/secondaryTextColor</item>
<item name="colorPrimaryDark">@color/darkPrimaryColor</item>
<item name="colorAccent">@color/accentColor</item>
<item name="actionOverflowMenuStyle">@style/CMOptionsMenu</item>
</style>
I have not decided any height of image for action bar but I am getting very large image in a mobile as shown in the image.
please help me to solve this problem.
Upvotes: 1
Views: 4793
Reputation: 1068
Replace your toolbar code with this one
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:gravity="center_vertical"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark" />
Upvotes: 1
Reputation: 3831
For your tool bar remove the height wrap_content
and put like this
android:layout_height="?attr/actionBarSize"
UPDATE
Try like this
Drawable logo=getResources().getDrawable(R.drawable.boy_thumbnail);
getSupportActionBar().setLogo(logo);
for (int i = 0; i < toolbar.getChildCount(); i++) {
View child = toolbar.getChildAt(i);
if (child != null)
if (child.getClass() == ImageView.class) {
ImageView iv2 = (ImageView) child;
if ( iv2.getDrawable() == logo ) {
iv2.setAdjustViewBounds(true);
}
}
}
Upvotes: 4