- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
应用程序使用 actionbarsherlock,但主要事件获取 getsupportactionbar 返回 null。
AndroidManifest.xml:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Light1Theme" >
<activity
android:name=".activity.LogonActivity"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustUnspecified|stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
<style name="Light1Theme" parent="Theme.Sherlock.Light">
extends SherlockActivity implements OnSharedPreferenceChangeListener {
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.logon);
try{
final ActionBar ab = getSupportActionBar();
//return null
ab.setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));
getSupportActionBar().setIcon(R.drawable.hospital);
}catch(Exception e){
Log.e("", e.getMessage());
}
最佳答案
几个小时前我遇到了同样的问题,结果证明,问题的根源在于我使用了一个没有标题栏的主题。
This reply来自 Jake Wharton,actionbarsherlock 的开发者将帮助您解决问题。
简而言之:在安卓版本 ICS 和更新版本上,设置属性 android:windowNoTitle
将影响操作栏的显示(因为它是这些版本的核心功能)。
ABS 已将其包裹成 windowNoTitle
(没有命名空间/默认 abs 命名空间),因此根据您的应用程序安装的 android 版本,您将获得正确的显示。
如果你有这条线
<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>
关于actionbarsherlock getSupportActionBar() 在 android4.0 中返回 null,但在 2.3.3 中是可以的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11944855/
有人建议我从 ActionBarActivity 扩展我的 Activity 类 这是之前的代码: import android.support.v7.app.ActionBar; import an
任何人都请帮助我,我是 ActionBar 的新手 如何为 API 7 调用 getSupportActionBar(),在我的 Activity 类中我无法调用 getSupportActionBa
这个问题在这里已经有了答案: How do I change the background color of the ActionBar of an ActionBarActivity using
这是我的代码: package com.greenwichdancestudio.greenwichdance; import java.util.ArrayList; import java.uti
我知道这个问题已经发布了很多次,但即使我尝试了很多来自 Stack Overflow 的解决方案,我仍然无法解决。 import android.support.v4.app.FragmentActi
在我开始第二个 Activity 后,没有 ActionBar。当我调用 GetSupportActivity 时,它返回 null。为什么?我有 minSdkVersion 10 和 targetS
在 onCreate() Activity 方法中,我有用于 ToolBar 的代码: toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupp
所以,我有这个小 Activity ,我想添加一个后退按钮(标准箭头一)我在这里搜索答案,发现了这个小代码: public class PozosFluyentes extends AppCompat
我正在尝试在我的应用程序上播放 YouTube 视频。我知道这可以通过将 Activity 扩展为 YouTubeBaseActivity 来实现,这样做我无权访问我的工具栏。 mActionBar
我正在学习使用滑动菜单库。到目前为止,我可以使用带有 2 个 fragment 的 viewpager。但我无法使用操作栏选项卡来导航这些 fragment 。这是我的代码 @Override pub
我正在尝试使用 ActionBarSherlock 库在旧设备中使用操作栏。我的应用程序在 Android(4.2-真实设备) 上运行。但是,当我尝试在 Android 2.3.4 上运行的旧版 Ga
我正在尝试制作一个抽屉导航,但我在 getSupportActionBar() 部分遇到了问题。它显示 - 无法解析方法“getSupportActionBar()”。我不知道为什么。请有人帮助我。下
这是我的代码: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ //android.support.v7.app.Ac
我正在尝试在我的应用程序上播放 YouTube 视频。我知道这可以通过将 Activity 扩展为 YouTubeBaseActivity 来实现,我无权访问我的工具栏。 mActionBar = (
这件事让我抓狂。我似乎无法让我的应用程序正确编译。我通过复制 jar 文件,将它们放入 libs 文件夹,右键单击并将它们添加为库,在我的应用程序中添加了支持库。 我已尝试扩展 ActionBarac
首先,我知道这个问题之前已经被问过,我花了一个小时查看其他解决方案,大部分来自 - getActionBar() returns null ,但没有一个有效,因此另一双眼睛也许能够做一些事情。 其他类
我正在使用 Android Studios,但是,我无法添加以下两种方法,因为它说它无法解析它们。 getSupportActionBar().setDisplayHomeAsUpEnabled(t
我正在从我的根 Activity 中启动一个新 Activity (TVMPDFActivity)。我正在使用 Android 注释,所以这就是我启动 Activity 的方式: TVMPDFActi
我正在使用 getSupportActionBar().setIcon(R.drawable.ic_transparent); 来设置工具栏的图标。如何从该图标获取 ImageView?我需要图标的
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 5 年前。 我正在尝试在我的 Android
我是一名优秀的程序员,十分优秀!