我正在尝试在android中创建自定义操作栏。我想摆脱顶部和底部的空白。有人可以告诉我该怎么做吗?
图片在这里
下面是我的样式代码。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="actionBarStyle">@style/ProfileSetUpActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="ProfileSetUpActionBar"
parent="Widget.AppCompat.Toolbar">
<!-- Support library compatibility -->
<item name="contentInsetStart">0dp</item>
<!--<item name="background">@android:color/transparent</item>-->
</style>
</resources>
下面是操作栏的布局xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0080ff">
<ImageButton
android:layout_width="0dp"
android:layout_weight="0.15"
android:layout_height="match_parent"
android:background="@drawable/back_arrow"/>
<TextView
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="match_parent"
android:textColor="#ffffff"
android:text="Sample" />
<Button
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="match_parent"
android:text="Join"
android:background="#0080ff"/>
</LinearLayout>
活动代码。我的活动是从AppCompactActivity扩展的。
ActionBar actionBar = getSupportActionBar();
LayoutInflater mInflater = LayoutInflater.from(this);
View profileSetUpView = mInflater.inflate(R.layout.profile_setup_actionbar, null);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
ActionBar.LayoutParams layout = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setCustomView(profileSetUpView,layout);
actionBar.show();
EDIT1:我对上述问题的下一个挑战是,我的自定义布局中的Join按钮的文本显示为JOIN。我希望成为“加入”而不是“加入”。有人可以帮我这个忙吗?
我修改了我的样式,如下所示。但是没有任何效果。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="actionBarStyle">@style/ProfileSetUpActionBar</item>
<item name="android:actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
</style>
<!-- ActionBar styles -->
<style name="ProfileSetUpActionBar"
parent="Widget.AppCompat.Toolbar">
<!-- Support library compatibility -->
<item name="contentInsetStart">0dp</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
我通过添加以下样式来解决第二个挑战
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="actionBarStyle">@style/ProfileSetUpActionBar</item>
<item name="android:textAppearanceButton">@style/CustomTheme.ButtonTextAppearance</item>
</style>
<style name="CustomTheme.ButtonTextAppearance" parent="@style/Base.TextAppearance.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
编辑-2:我的第三个挑战是最后一个加入按钮,在此勾号旁边的链接中有一个细分隔线。我尝试将以下代码添加到Apptheme中的样式中,但无法摆脱它。
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="actionBarStyle">@style/ProfileSetUpActionBar</item>
<item name="android:textAppearanceButton">@style/CustomTheme.ButtonTextAppearance</item>
<item name="android:actionBarDivider">@null</item>
<item name="actionBarDivider">@null</item>
<item name="android:showDividers">none</item>
<item name="android:dividerVertical">@null</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:divider">@null</item>
</style>
有人可以帮我解决这个问题吗?
自定义视图插入了一些填充。解决方法:您可以将视图的颜色设置为与操作栏相同,以使空间不可见。或将颜色设置为操作栏
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句