Cli*_*fus 99
编辑:确保将此drawable设置为LOGO,而不是像某些评论者那样设置应用程序图标.
只需创建一个XML drawable并将其放在资源文件夹"drawable"中(没有任何密度或其他配置).
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/my_logo"
android:right="10dp"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
最后一步是将此新drawable设置为清单中的徽标(或活动中的Actionbar对象)
祝好运!
Min*_*sky 69
我修改了Cliffus的回答并在我的动作栏样式定义中分配了logo-drawable,例如在res/style.xml中这样:
<item name="android:actionBarStyle">@style/MyActionBar</item>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#3f51b5</item>
<item name="android:titleTextStyle">@style/ActionBar.TitleText</item>
<item name="android:textColor">#fff</item>
<item name="android:textSize">18sp</item>
<item name="android:logo">@drawable/actionbar_space_between_icon_and_title</item>
</style>
Run Code Online (Sandbox Code Playgroud)
drawable在res/drawable/actionbar_space_between_icon_and_title.xml中看起来像Cliffus的一个(这里有默认的应用程序启动器图标):
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_launcher"
android:right="20dp"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
在android_manifest.xml中,您仍然可以设置不同的应用程序图标("桌面"上的启动器图标.此处的任何不同徽标定义都可在没有操作栏的活动中看到.
Rah*_*ani 52
我也面临类似的问题,在我的情况下,我必须根据内容动态设置每个活动的标题.
所以这对我有用.
actionBar.setTitle(" " + yourActivityTitle);
Run Code Online (Sandbox Code Playgroud)
如果你想要的只是间距,这是我能想到的最简单的解决方案.
小智 40
这就是我能够在主页图标和标题之间设置填充的方法.
ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(left, top, right, bottom);
Run Code Online (Sandbox Code Playgroud)
我找不到通过ActionBar xml样式自定义的方法.也就是说,以下XML不起作用:
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/ActionBarTitle</item>
<item name="android:icon">@drawable/ic_action_home</item>
</style>
<style name="ActionBarTitle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">18sp</item>
<item name="android:paddingLeft">12dp</item> <!-- Can't get this padding to work :( -->
</style>
Run Code Online (Sandbox Code Playgroud)
但是,如果您希望通过xml实现此目的,这两个链接可能会帮助您找到解决方案:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
(这是用于在操作栏中显示主页图标的实际布局) https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/action_bar_home.xml
the*_*ott 32
这是Material Design中的常见问题,因为您可能希望将工具栏标题与下面片段中的内容对齐.为此,您可以使用toolbar.xml布局中的属性contentInsetStart ="72dp"覆盖默认的"12dp"填充,如下所示
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_theme_color"
app:contentInsetStart="72dp"/>
Run Code Online (Sandbox Code Playgroud)
然后在你的活动中,打电话
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
toolbar.setTitle("Title Goes Here");
Run Code Online (Sandbox Code Playgroud)
你最终得到了这个:
Aji*_*jit 29
对我来说,只有以下组合起作用,从API 18到24测试
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
Run Code Online (Sandbox Code Playgroud)
在"app"中的位置是: xmlns:app="http://schemas.android.com/apk/res-auto"
例如.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/SE_Life_Green"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
>
.......
.......
.......
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
try*_*ryp 29
如果您使用AppCompat中的工具栏(android.support.v7.widget.Toolbar,> = Revision 24,2016年6月),则可以使用以下值更改图标和标题之间的填充:
app:contentInsetStartWithNavigation="0dp"
Run Code Online (Sandbox Code Playgroud)
为了改进我的答案,您可以直接在活动中的工具栏上使用它,也可以为工具栏创建新的布局文件.在这种情况下,您只需要在每个所需视图上使用include属性导入工具栏的@id.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
然后,您可以在activity.xml上导入布局
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
使用titleMarginStart
作品给我.Xamarin示例:
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleMarginStart="24dp"/>
Run Code Online (Sandbox Code Playgroud)
像这样设置徽标:
mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
SetSupportActionBar(mToolbar);
SupportActionBar.SetLogo(Resource.Drawable.titleicon32x32);
SupportActionBar.SetDisplayShowHomeEnabled(true);
SupportActionBar.SetDisplayUseLogoEnabled(true);
SupportActionBar.Title = "App title";
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
96203 次 |
最近记录: |