【问题标题】:ActionBar Compat ActionBarActivity setTitle does not work in Android 2.XActionBar Compat ActionBarActivity setTitle 在 Android 2.X 中不起作用
【发布时间】:2014-02-24 02:46:16
【问题描述】:

我的问题和this issue一样。

我已经按照this instruction 设置了 Android 支持库。 (我正在使用支持库,修订版 19.0.1)

在这个问题中,谷歌的工作人员说“这已在支持库 v19 中修复”。但是,它在我的设备(姜饼)中不起作用。

我试图找到解决方案,但找不到。有什么想法吗?

【问题讨论】:

  • 你有没有这样调用过getSupportActionBar().setTitle("ActionBar Support Demo"); ??例如:tech.adarshahd.net/using-support-actionbar
  • @LOG_TAG 谢谢,我没试过。 ActionBarActivity.setTitle() 不工作,但 getSupportActionBar().setTitle() 工作正常!

标签: android android-actionbar-compat


【解决方案1】:

第 1 步:将 appcompat 从您的 adt-bundle 文件夹导入到您的 eclipse 中。

链接:

adt-bundle-windows-x86-20130917\adt-bundle-windows-x86-20130917\sdk\extras\android\support\v7\appcompat

第 2 步:将其设为库。

-右键点击android-support-v7-appcompat。

-点击属性。

-点击Android(下方资源)。

-将其标记为“isLibrary”。

第 3 步:在您的项目中使用它。

-右键单击您的项目。

-点击属性。

-点击Android(下方资源)。

-点击“添加”。

-单击 android-support-v7-appcompat 使其成为您项目的库。

第 4 步:在您的 Activity 中调用 Action Bar。

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

步骤 5:如果不存在,则在“Values”文件夹中创建一个 styles.Xml 文件,并在提及代码下添加。

<resources>

<style name="ProgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal"/>

</resources>

第 6 步:更新清单文件,将其添加到“应用程序”下。

android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar"

最好的,如果您遇到任何问题,请回复。

【讨论】:

  • 谢谢! getSupportActionBar().setTitle() 是一个解决方案!
  • 如果您从片段中执行此操作,则必须将FragmentActivity 类型转换为ActionBarActivity 才能调用getSupportActionBar。
【解决方案2】:

使用getSupportActionBar().setTitle()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多