所以我使用ActionBarSherlock并决定切换到新的ActionBarCompat.使用ABS,可以使用本文中描述的方式隐藏ActionBar: 如何在创建活动之前隐藏操作栏,然后再次显示它?
但是,随着ActionBarCompat上API14的应用程序崩溃,因为当你设置android:windowActionBar
为false
的getSupportActionBar()
方法返回null,即使你已经宣布getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
进入onCreate()
方法.
有趣的是,如果你打电话getActionBar()
,你得到的对象,一切正常.
那么,这是一个错误还是我错过了什么?欢迎任何想法!
styles.xml
文件:
<style name="Theme.MyApp" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
MyActivity.java
文件:
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the action bar feature. This feature is disabled by default into the theme
// for specific reasons.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
...
// By default the action bar is hidden.
getSupportActionBar().hide();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用VectorDrawable
API21,但Android会从xxhdpi
文件夹中加载PNG资源.我目前的res
结构如下:
我的XML布局:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test_icon"/>
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以解决这个问题?根据我的理解,Android将始终选择PNG资源,但如果是这样的话,那么如何使用VectorDrawables
for API21
和PNG来获得较低的API?
[更新1]
如果我们使用drawable-xxhdpi-21
资源文件夹,Android将选择向量而不是PNG资源.但是,这意味着我们将不得不对其他密度的文件的副本(或符号连接),以及(如xhdpi
,hdpi
等)
android ×2