GVKun编程网logo

android – 自定义ActionBar TabBar(ActionBarSherlock)(android自定义progressbar)

14

在这篇文章中,我们将为您详细介绍android–自定义ActionBarTabBar(ActionBarSherlock)的内容,并且讨论关于android自定义progressbar的相关问题。此外

在这篇文章中,我们将为您详细介绍android – 自定义ActionBar TabBar(ActionBarSherlock)的内容,并且讨论关于android自定义progressbar的相关问题。此外,我们还会涉及一些关于ActionBarSherlock 4.1最低支持Android2.x版本?、actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok、ActionBarSherlock — 无缝集成ActionBar、ActionBar或ActionBarSherlock-平滑隐藏/显示ActionBar的知识,以帮助您更全面地了解这个主题。

本文目录一览:

android – 自定义ActionBar TabBar(ActionBarSherlock)(android自定义progressbar)

android – 自定义ActionBar TabBar(ActionBarSherlock)(android自定义progressbar)

我已经坚持了几天这个问题了.任何人都可以帮我自定义ActionBar下面显示的选项卡(NavigationMode是NAVIGATION_MODE_TABS)?

我基本上想要更改选项卡的背景颜色和当前所选选项卡的下划线颜色.到目前为止,这是我所做的,但它不起作用.我正在使用ActionBarSherlock.

<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>

    <item name="actionBarTabBarStyle">@style/customActionBarTabStyle</item>
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabStyle</item>

    <item name="actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>

    <item name="actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
    <item name="android:actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
</style>

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@color/red</item>

    <item name="android:textSize">12dp</item>

</style>

<style name="customActionBarTabBarStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabBar">
    <item name="android:background">@color/red</item>
</style>

<style name="customActionBarTabTextStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabText">
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="Widget.Theme.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">#A9E2F3</item>
    <item name="background">#A9E2F3</item>
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
</style>

<style name="Theme.Styled.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="Animations" />

解决方法

我不确定你是否还需要这个,但我会将答案发给其他人看.您可以在customActionBarTabStyle的后台Drawable中将其设置为Drawable资源:
<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/actionbar_tabs_selector</item>
    <item name="android:textSize">12dp</item>
</style>

资源应该是一个选择器,在这些行中:

<!-- This is the "@drawable/actionbar_tabs_selector" layout !-->

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_selected"/>

    <!-- pressed state -->
    <item android:state_pressed="true" android:drawable="@drawable/actionbar_tab_style_selected" />

    <!-- Focused state -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>

</selector>

所以这里的资源是2层列表.一个用于选项卡处于非活动状态,一个用于选项卡处于活动状态时.因此,您可以根据所选状态设置2个图层列表.

单个图层列表可能如下所示:

<!-- This is the "@drawable/actionbar_tab_style_nselected" layout !-->

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Bottom Line -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/HCL_orange" />
        </shape>
    </item>

    <!-- Tab color -->
    <item android:bottom="2dip">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>
</layer-list>

因此,第一项是底线,您可以将其定义为当前所选Tab的下划线颜色,第二项是整个选项卡的颜色.

ActionBarSherlock 4.1最低支持Android2.x版本?

ActionBarSherlock 4.1最低支持Android2.x版本?

@鉴客 你好,想跟你请教个问题:

ActionBarSherlock 4.1最低支持Android2.x版本?

actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok

actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok

转载地址:http://stackoverflow.com/questions/11944855/actionbarsherlock-getsupportactionbar-return-null-in-android4-0-but-in-2-3-3-i


不想看那么多 E 文的:我直接说关键部分

找到





改完就可以了!

ActionBarSherlock — 无缝集成ActionBar

ActionBarSherlock — 无缝集成ActionBar

如果你想在3.0+系统上使用系统的ActionBar而在3.0以前的系统上使用自定义的ActionBar,那么ActionBarSherlock就可以帮助你了.

ActionBarSherlock 是Android compatibility library 的一个扩展, 不知道什么原因 Android 兼容开发包没有包含ActionBar. 所以就有了ActionBarSherlock . 其使用方式和 兼容开发包类似.

下载地址: https://github.com/JakeWharton/ActionBarSherlock/zipball/3.4.2

有两种方式把ActionBarSherlock类库引入到你的项目中,:

  1. 使用Eclipse和ADT插件.
解压下载的文件, 用里面的library目录中的代码创建一个Android项目.然后在项属性中的Android选项里面设置该项目为library项目. 这样就可以在其他Android项目中使用了.
  1. 使用Maven.
如果你使用Maven来打包的话, 只需要添加一个依赖项即可:
<dependency>
  <groupId>com.actionbarsherlock</groupId>
  <artifactId>library</artifactId>
  <version>3.4.2</version>
  <type>apklib</type>
</dependency>
注意:需要在你项目pom.xml的资源库中添加 r.jakewharton.com/maven/release/.
另外 如果项目已经使用了Android兼容开发包,需要把他们移除, 因为ActionBarSherlock 已经包含了这些代码.
为了在3.0以前系统上使用ActionBar需要导入下面的类:
android.support.v4.app.ActionBar
android.support.v4.view.Menu
android.support.v4.view.MenuItem

这些类的名称和3.0系统中的一样.

使用ActionBar API需要你的Activity继承至FragmentActivity, 通过调用FragmentActivity.getSupportActionBar()函数来处理ActionBar事件, 而不能调用3.0系统中的getActionBar()函数.
ActionBar类的API和3.0系统中的一样, 详情参考这里的API文档.
在3.0+系统上使用原生的ActionBar实现, 如下图:
使用原生ActionBar

使用原生ActionBar

在3.0以前系统上使用自定义实现, 如下图:
使用自定义ActionBar

使用自定义ActionBar

ActionBar或ActionBarSherlock-平滑隐藏/显示ActionBar

ActionBar或ActionBarSherlock-平滑隐藏/显示ActionBar

我正在使用ActionBarSherlock,并尝试使用以下方法隐藏/显示全屏图像的ActionBar:

getSupportActionBar.hide();

getSupportActionBar.show();

但这确实是跳跃和尴尬的。有没有办法使它更平滑,或者应用平移/不透明动画?

在进一步检查ABS源并观察其行为后,似乎至少定义了最少的动画。对于标准ActionBar,不能说相同的话。

为了完整起见,这是我从ImageView.click调用的相关代码:

if( shouldRender )
{
  . . .

  getSupportActionBar().hide();

  getWindow().addFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN );
}
else
{
  . . .

  getSupportActionBar().show();

  getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN );
}

值得注意的是,标志的设置/清除也会引起跳转,但是跳转不那么明显,所以我将在以后解决它,如果有的话。

编辑:
这(通过ABS的创造者)似乎状态,它在本地的ActionBar是不可能的。我想我只可以编辑两个XML文件来定义他的动画,但这不会给我带来完整的平台渗透力。

今天关于android – 自定义ActionBar TabBar(ActionBarSherlock)android自定义progressbar的讲解已经结束,谢谢您的阅读,如果想了解更多关于ActionBarSherlock 4.1最低支持Android2.x版本?、actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok、ActionBarSherlock — 无缝集成ActionBar、ActionBar或ActionBarSherlock-平滑隐藏/显示ActionBar的相关知识,请在本站搜索。

本文标签: