[英]Do I need to specify the theme for each activity in the AndroidManifest.xml
[英]Android Theming: How do I reference a drawable out of the theme selected in AndroidManifest.xml?
我将我的应用程序从自定义标题栏切换到ActionBar支持库,因为我喜欢ActionBar提供的功能,并且由于仅3.0+,我以前避免了它。 我的ActionBar正常工作,这很好,但是我的应用程序在屏幕底部也有一个较低的栏,我希望与顶部的ActionBar保持相同的外观。 由于ActionBar似乎使用图像背景(九个补丁PNG),而不是像我以前那样定义颜色,因此我需要从布局xml访问动作条底部可绘制对象的drawable,并将其用作底部条形的背景。
我浏览了支持v7库,发现了诸如@ drawable / abc_cab_background_bottom_holo_dark之类的可绘制对象,并手动输入该对象可很好地适用于深色主题。 但是,我想添加一些东西,它可以自动为AndroidManifest中指定的主题提取正确的可绘制对象,无论它是浅色还是深色主题。
这是有问题的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/abc_ab_bottom_solid_light_holo">
并在AndroidManifest.xml中:
<application android:icon="@drawable/icon"
android:allowBackup="true"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:theme="@style/Theme.AppCompat.Light" >
我发现的所有内容都在讨论如何使用您自己的主题编辑ActionBar,但我想做相反的事情,使用基于股票appcompat主题的股票ActionBar可绘制对象来编辑自己的酒吧。 具体来说,我应该为android:background =放置什么以引用当前主题的版本:
<item name="actionModeSplitBackground">@drawable/abc_cab_background_bottom_holo_dark</item>
如v7 / appcompat / res / values / themes_base.xml中所定义?
嘿,从我的ActionBar示例应用程序开始。
我正在以编程方式这样做:
XML部分:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg_striped_img"
android:tileMode="repeat"
android:dither="true" />
在XML部分中,将您的drawable设置为图像源,然后在程序中将XML用作BitampDrawable
在OnCreate上:
//striped layout
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
BitmapDrawable bgSplit = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped_split);
bgSplit.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setSplitBackgroundDrawable(bgSplit);
}
编辑: R.drawable.bg_striped
和R.drawable.bg_striped_split
这两个都是如上所述的XML文件,bg_striped用于更改actionBar背景,bg_striped_split用于更改Split菜单背景。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.