开发者

android themes and library projects

I have a library project, which is a TabActivity, and redefined some styles to draw my custom ToggleButton with a different background. I added a styles.xml file:

     <resources>
         <style name="custom_button" parent="@android:style/Widget.Button">
             <item name="android:gravity">center_vertical|center_horizontal</item>
             <item name="android:textColor">#FFFFFFFF</item>
             <item name="android:shadowColor">#FF000000</item>
             <item name="android:shadowDx">0</item>
             <item name="android:shadowDy">-1</item>
             <item name="android:shadowRadius">0.2</item>
             <item name="android:textSize">16dip</item>
             <item name="android:textStyle">bold</item>
             <item name="android:background">@drawable/btn_custom</item>
             <item name="android:focusable">true</item>
             <item name="android:clickable">true</item>
         </style>
     </resources>

And a themes.xml file:

<resources>
    <style name="custom_theme" parent="android:style/Theme.NoTitleBar">
        <item name="android:buttonStyleToggle">@style/custom_button</item&开发者_运维问答gt;
    </style>
</resources>

And applied the theme in the manifest file.

Everything works ok if I start the activity directly instead of being a library project. But if I launch this activity (using an intent) from another project, the custom theme is not applied to the toggle buttons, they look like the default android theme. Other resources are loaded, the library project has some drawables and they are painted ok. I'm not using assets.

Other weird thing is that if I change the button text:

ToggleButton tbLocal = (ToggleButton)findViewById(R.id.tblocal);
tbLocal.setText("Local");

... when the activity is started, text is not changed and the default text (YES/NO) is used. If I start the library project activity directly this doesn't happen neither.

What can be wrong?


You have two manifest files: one in your library project and another in your application project. You need to apply your theme in the application AndroidManifest.xml file, and not in the library one (actually it is useless to define <activity> element in the library project manifest).

For toggle button on/off text use the following:

ToggleButton tbLocal = (ToggleButton)findViewById(R.id.tblocal);
tbLocal.setTextOn("LocalOn");
tbLocal.setTextOff("LocalOff");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜