小编もっく*_*っくん的帖子

ActionBarCompat:在创建活动之前隐藏ActionBar(bug?)

所以我使用ActionBarSherlock并决定切换到新的ActionBarCompat.使用ABS,可以使用本文中描述的方式隐藏ActionBar: 如何在创建活动之前隐藏操作栏,然后再次显示它?

但是,随着ActionBarCompat上API14的应用程序崩溃,因为当你设置android:windowActionBarfalsegetSupportActionBar()方法返回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)

android android-actionbar android-actionbar-compat

16
推荐指数
2
解决办法
1万
查看次数

VectorDrawable:Android加载xhdpi PNG而不是矢量资源

我正在尝试使用VectorDrawableAPI21,但Android会从xxhdpi文件夹中加载PNG资源.我目前的res结构如下:

  • 水库
    • 绘制,xxhdpi
      • test_icon.png
    • 绘制-21
      • test_icon.xml

我的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资源,但如果是这样的话,那么如何使用VectorDrawablesfor API21和PNG来获得较低的API?

[更新1]

如果我们使用drawable-xxhdpi-21资源文件夹,Android将选择向量而不是PNG资源.但是,这意味着我们将不得不对其他密度的文件的副本(或符号连接),以及(如xhdpi,hdpi等)

android android-layout android-5.0-lollipop

6
推荐指数
1
解决办法
914
查看次数