2014-01-06 34 views
0

我将自己的应用从自定义标题栏切换到ActionBar支持库,因为我喜欢ActionBar提供的功能,而且之前我仅仅因为3.0+而避免了它。我有ActionBar正常工作,这是很好的,但我的应用程序也有一个较低的酒吧在屏幕的底部,我想保持与顶部的ActionBar相同的外观。由于它看起来像ActionBar使用图像背景(九个补丁PNG),而不是像我以前所做的那样定义颜色,所以我需要从我的布局xml访问可拖动的操作栏底部的drawable,并将其用作底部栏的背景。Android主题:如何从AndroidManifest.xml中选择的主题引用drawable?

我查看了支持v7库,发现了drawable/abc_cab_background_bottom_holo_dark和手动输入,可以很好地处理黑暗的主题。不过,我想放入一些能够自动为AndroidManifest中指定的主题提取正确的drawable的东西,无论是明亮还是黑暗的主题。

这里是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" > 

一切我已经找到了一直在讨论如何与自己的主题编辑动作条,但我想做相反的事情,根据股票appcompat主题编辑我自己的股票,股票的ActionBar可绘制。具体而言,做什么,我把为Android:背景=参考的当前主题的版本:

<item name="actionModeSplitBackground">@drawable/abc_cab_background_bottom_holo_dark</item> 

为V7 /程序兼容性/ RES /价值/ themes_base.xml界定?

回答

0

嘿从我的示例应用程序的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部分设置你的绘制图片来源然后使用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_stripedR.drawable.bg_striped_split

这两者都是你的XML文件,上面明确和bg_striped是改变你的动作条背景与bg_striped_split是改变你的拆分菜单背景..

+0

哪里是R. drawable.bg_striped_split定义了吗? – CalcProgrammer1

+0

Just Edited .. !!并请告诉我,如果它的工作与否.. :) – arraystack