【问题标题】:custom tile background in sherlockActionbar夏洛克操作栏中的自定义平铺背景
【发布时间】:2013-05-02 05:00:18
【问题描述】:

我正在使用 sherlock 操作栏创建一个应用程序.. 在这里我想为我的自定义 title_background 充气...

这就是我需要的......

这是我的title_background_layout

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:gravity="center"
android:paddingLeft="5dip"
android:background="@drawable/titlebar">

<ImageView
    android:id="@+id/header"
    android:src="@drawable/netmd"
    android:layout_width="140dp"
    android:layout_height="40dp"/>

我在我的主要活动中设置了标题背景....

public class MainActivity extends SherlockActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);      
    setContentView(R.layout.activity_main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_background);      
}

但 logcat 中显示一些错误。

 05-02 10:17:36.302: E/AndroidRuntime(706): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.netmdapp1/com.example.netmdapp1.MainActivity}:

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

我找到了另一个解决方案,再见创建我自己的风格......

我的样式 xml 文件是....

<style name="CustomActioBar" parent="Widget.Sherlock.ActionBar">
        <item name="android:background">@drawable/titlebar</item>
        <item name="background">@drawable/titlebar</item>
    </style>
    <!-- Application theme. -->

    <style name="AppTheme" parent="Theme.Sherlock.Light">
        <item name="actionBarStyle">@style/CustomActioBar</item>


    </style>

但它仅适用于 android 版本 2.3.3 它不适用于更高版本。

不,它也不能在我的手机上工作......

【问题讨论】:

    标签: android actionbarsherlock titlebar custom-titlebar


    【解决方案1】:

    如果你想为 sherlock actionbar 设置 CustomView,请遵循此代码

    final ActionBar ab = getSupportActionBar();        
    ab.setDisplayShowCustomEnabled(true);
    
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.title_background, null);
    ab.setCustomView(view);
    

    编辑: 如果您不想显示徽标和标题,只需将这些参数与上述操作栏代码一起添加

    ab.setDisplayHomeAsUpEnabled(false);
    ab.setDisplayShowHomeEnabled(false);
    ab.setDisplayShowTitleEnabled(false);
    

    【讨论】:

    • thnx Raja....它的工作...但它没有填满我的屏幕...它看起来像.....徽标标题 {inflated layout} menuButton
    • 你想如何展示。您不想显示徽标和标题?让我知道我也会为此分享代码..
    • 是的,我不想显示我的徽标和标题...我需要填满我的屏幕
    • yaaa 但现在我的布局是左对齐的......我的 actionBar 的其余部分是空的......默认颜色显示......
    • 改变你的图像视图宽度 android:layout_width="fill_parent"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多