user3709688
user3709688

Reputation: 13

Android : Need help to set padding in styles.xml

This is my activity layout, i want to add a style for this activity in Manifest and the textview should not be visible in layout. I know i can do it programmatically as setVisibility(View.GONE); but it is a need and i have to do it with styles and style is to be given in manifest only. This is my layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

    <ScrollView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="@drawable/scroll_back">

        <RelativeLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent">

            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="vertical">

                <!--i am talking about this textview-->

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_gravity="center"
                    android:text="Some Text"
                    android:padding="5dp"/>

                <!-- ends here.-->



                <TextView
                    android:layout_height="wrap_content"
                    android:text="Enter Name:"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_width="wrap_content"/>

                <EditText
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:layout_width="match_parent"
                    android:hint="e.g John"
                    android:id="@+id/editText1"/>

                <Button
                    android:layout_height="wrap_content"
                    android:text="Save"
                    android:layout_width="match_parent"
                    android:id="@+id/button1"/>

            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

</LinearLayout>

Upvotes: 1

Views: 8614

Answers (2)

Sushant Gosavi
Sushant Gosavi

Reputation: 3845

This work for me put this in your res/value/style.xml

<style name="FontAwsomeFormFields">
        <item name="android:paddingLeft">@dimen/smallPadding</item>
        <item name="android:paddingRight">@dimen/smallPadding</item>
        <item name="android:paddingTop">@dimen/largPadding</item>
        <item name="android:paddingBottom">@dimen/smallPadding</item>
        <item name="android:layout_margin">@dimen/smallPadding</item>
        <item name="android:textSize">@dimen/normalTextSize</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:singleLine">true</item>
        <item name="android:textColor">@color/white</item>
    </style> 

than used in XML file

         <com.indussoft.lms.customUI.FontAwsomeTextView
                android:id="@+id/tvHomeIcon"
                style="@style/FontAwsomeFormFields"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/fa_long_arrow_left"
                android:textSize="@dimen/largeTextSize" />

Upvotes: 1

Kishan Dhamat
Kishan Dhamat

Reputation: 3784

Do this in your style.xml:

 <style name="MyTextviewStyle" parent="@android:style/Widget.TextView"> 
     <item name="android:visibility">gone</item>      
</style>

Now in your textView do this:

                <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:text="Some Text"
                style="@style/MyTextviewStyle"
                android:padding="5dp"/>

Upvotes: 0

Related Questions