我正在尝试在主要活动的应用程序工具栏的中央设置徽标,但是由于徽标为高清格式,因此会导致工具栏增大其大小以适应徽标的大小。有没有一种方法可以按比例减小徽标大小,以便在工具栏上正确设置?
这是我的代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable.logotrans);
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="@android:color/white"></android.support.v7.widget.Toolbar>
<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">@color/white</item>
</style>
结果如下:
Android中的工具栏是一个ViewGroup。因此,您可以将小部件作为其子项放置在工具栏内。另外,要使日志的大小与工具栏的大小相同,请为工具栏指定一定的高度,并将“图像”大小设置为match_parent。例如:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/black">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_clock"
android:layout_gravity="center_horizontal"
/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
我仍然建议减少徽标的大小,因为它将来可能会导致内存泄漏。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句