【问题标题】:How to integrate old android styles into titanium alloy如何将旧安卓风格融入钛合金
【发布时间】:2023-03-14 22:35:01
【问题描述】:

我正在将我的一个 android 应用程序转换为钛合金,我有一些选择器 xml,用于保存在 res/drawable 文件夹 (custom_btn_genoa.xml) 中的按钮,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:state_pressed="true" >
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#20534e" />
         <gradient  android:angle="-90"  android:startColor="#062d30" android:endColor="#4c898e"  />            
     </shape>
 </item>
<item android:state_focused="true">
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#20534e" />
         <solid  android:color="#125156"/>       
     </shape>
 </item>  
<item >
    <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#20534e" />
         <gradient  android:angle="-90"  android:startColor="#4c898e" android:endColor="#125156" />            
     </shape>
 </item>
</selector>

然后是我的按钮样式(values/styles.xml)

<style name="btnStyleGenoa" parent="@android:style/Widget.Button">
   <item name="android:textSize">15sp</item>
   <item name="android:textStyle">bold</item>
   <item name="android:textColor">#FFFFFF</item>
   <item name="android:gravity">center</item>
   <item name="android:shadowColor">#000000</item>
   <item name="android:shadowDx">1</item>
   <item name="android:shadowDy">1</item>
   <item name="android:shadowRadius">0.6</item>
   <item name="android:background">@drawable/custom_btn_genoa</item>
   <item name="android:padding">10dip</item>
   </style>

在钛中我可以设置文本大小、颜色等,但是如何在钛合金中轻松实现选择器 xml 的东西?

【问题讨论】:

    标签: android xml titanium titanium-alloy


    【解决方案1】:

    从 Android 样式到 Titanium 的转换不是一对一的,而是要普遍适用于多个平台(iOS、Android、Windows、Blackberry)。在这种情况下(如果您尝试模拟按钮选择器),这是内置于 Titanium 中的,这是您所拥有的合金 xml 选择器的近似值:

    <Alloy>
            <Button id="button" title="Hello" 
                    top="10" width="100" height="50" 
                    color="#FFF"
                    backgroundFocusedColor="#125156" 
                    backgroundColor="#125156"  
                    backgroundSelectedColor="#4c898e"/>
    </Alloy>
    

    backgroundFocused 和 Selected 分别指定用户与按钮交互时要使用的不同图像或颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多