4

I am facing the issue of formatting a simple textfield in Titanium Android.

Problem : I am not able to view the text field input value that I enter. If I print the logs its getting entered but not visible. In some devices I get cut-off text.

Below is my code :

In my .js file I have textfield as follows :

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
    });

In my tiapp.xml file :

<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>

Solution tried : I tried the solution provided in the link:

It says that you need to set height of TextField to "Ti.UI.SIZE" + add <supports-screens android:anyDensity="true"/> in your tiapp.xml file + add <property name="ti.ui.defaultunit">dp</property> in your tiapp.xml file.

If I set height of textfield as "Ti.UI.SIZE" it shows the input value but the height of textfield becomes too large for the screen because I have multiple textfields in my particular screen and it looks too weird with this height.

Any help will be appreciated.

Thanks.

Update : Issue is observerd in Android 4.4.4 and 5.0 OS.For other, its working fine.

grebulon
  • 7,697
  • 5
  • 42
  • 66
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69

1 Answers1

5

Finally, I solved it using custom theme named mytheme.xml added under platform folder--> android folder --> res folder--> values folder --> mytheme.xml

In 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>

In tiapp.xml:

under android tag :

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <application android:theme="@style/Theme.MyTheme"/>
</manifest>
</android>

Mike Kellogg
  • 1,168
  • 5
  • 15
  • 34
Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
  • Thanks, this helped me remove the ugly top/bottom padding from Android textfields. It's nonsense that Titanium doesn't expose the android:paddingTop and android:paddingBottom properties. – Justin Dec 05 '15 at 04:00
  • @Justin Also helped me remove the padding from top and bottom. I agree concerning the Titanium exposing top and and bottom padding! If you make any kind of text field small on android devices (and you obviously will if you are developing for phones) then the blue focus bar gets in the way and your text is entered above the textbox because of bottom padding. – Mike Kellogg May 24 '16 at 15:24
  • @Justin and Mike Would have been good if some of you had posted the code you used to do this. – Muhammad Qasim Aug 24 '17 at 06:30
  • I did the same but editText styles are not applying thought other items of "Theme.MyTheme" are working as expected. – Muhammad Qasim Aug 24 '17 at 07:07