Titanium 中的 TextField 格式(填充)问题 Android
TextField formatting (padding) issue in Titanium Android
我面临在 Titanium 中格式化简单文本字段的问题 Android。
问题:我无法查看我输入的文本字段输入值。如果我打印日志,它会被输入但不可见。在某些设备中,我得到截断的文本。
下面是我的代码:
在我的 .js 文件中,我有如下文本字段:
var t1 = Titanium.UI.createTextField({
value : Titanium.App.Properties.getString("userID"),
left : 130,
top : 25,
height : 30,
width : 140,
color : 'black',
font : {
fontSize : 12
},
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
在我的 tiapp.xml 文件中:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="@style/Theme.Titanium"/>
<supports-screens android:anyDensity="false"
android:largeScreens="false"
android:normalScreens="false" android:resizeable="false"
android:smallScreens="false" android:xlargeScreens="false"/>
</manifest>
</android>
解决方案已尝试:我尝试了link中提供的解决方案:
它说你需要将 TextField 的高度设置为“Ti.UI.SIZE” + 在你的 tiapp.xml 文件中添加 <supports-screens android:anyDensity="true"/>
+ 添加<property name="ti.ui.defaultunit">dp</property>
在你的 tiapp.xml 文件中。
如果我将文本字段的高度设置为“Ti.UI.SIZE”,它会显示输入值,但文本字段的高度对于屏幕来说太大了,因为我有多个文本字段在我的特定屏幕上,这个高度看起来太奇怪了。
任何帮助将不胜感激。
谢谢。
更新:问题在 Android 4.4.4 和 5.0 OS.For 其他版本中被观察到,它工作正常。
最后,我使用在 platform folder--> android folder --> res folder--> values folder --> mytheme.xml
下添加的名为 mytheme.xml 的自定义主题解决了这个问题
在mytheme.xml中:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Define a theme using the AppCompat.Light theme as a base theme -->
<style name="Theme.MyTheme" parent="@style/Theme.Titanium">
<!-- For Titanium SDK 3.2.x and earlier, use the Holo.Light or Light theme
<style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light">
-->
<item name="android:editTextStyle">@style/editText</item>
</style>
<style name="editText" parent="@android:style/Widget.EditText">
<item name="android:textCursorDrawable">@null</item>
<item name="android:textColor">#000000</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:background">#FFFFFF</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
</style>
</resources>
在tiapp.xml中:
在 android 标签下:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="@style/Theme.MyTheme"/>
</manifest>
</android>
我面临在 Titanium 中格式化简单文本字段的问题 Android。
问题:我无法查看我输入的文本字段输入值。如果我打印日志,它会被输入但不可见。在某些设备中,我得到截断的文本。
下面是我的代码:
在我的 .js 文件中,我有如下文本字段:
var t1 = Titanium.UI.createTextField({
value : Titanium.App.Properties.getString("userID"),
left : 130,
top : 25,
height : 30,
width : 140,
color : 'black',
font : {
fontSize : 12
},
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
在我的 tiapp.xml 文件中:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="@style/Theme.Titanium"/>
<supports-screens android:anyDensity="false"
android:largeScreens="false"
android:normalScreens="false" android:resizeable="false"
android:smallScreens="false" android:xlargeScreens="false"/>
</manifest>
</android>
解决方案已尝试:我尝试了link中提供的解决方案:
它说你需要将 TextField 的高度设置为“Ti.UI.SIZE” + 在你的 tiapp.xml 文件中添加 <supports-screens android:anyDensity="true"/>
+ 添加<property name="ti.ui.defaultunit">dp</property>
在你的 tiapp.xml 文件中。
如果我将文本字段的高度设置为“Ti.UI.SIZE”,它会显示输入值,但文本字段的高度对于屏幕来说太大了,因为我有多个文本字段在我的特定屏幕上,这个高度看起来太奇怪了。
任何帮助将不胜感激。
谢谢。
更新:问题在 Android 4.4.4 和 5.0 OS.For 其他版本中被观察到,它工作正常。
最后,我使用在 platform folder--> android folder --> res folder--> values folder --> mytheme.xml
在mytheme.xml中:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Define a theme using the AppCompat.Light theme as a base theme -->
<style name="Theme.MyTheme" parent="@style/Theme.Titanium">
<!-- For Titanium SDK 3.2.x and earlier, use the Holo.Light or Light theme
<style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light">
-->
<item name="android:editTextStyle">@style/editText</item>
</style>
<style name="editText" parent="@android:style/Widget.EditText">
<item name="android:textCursorDrawable">@null</item>
<item name="android:textColor">#000000</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:background">#FFFFFF</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_width">wrap_content</item>
</style>
</resources>
在tiapp.xml中:
在 android 标签下:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:theme="@style/Theme.MyTheme"/>
</manifest>
</android>