2

I'm having a strange trouble and didn't find any solutions on the web. I'm adding a TextView dynamically into a RelativeLayout, with custom fonts, and sometimes the text appears underlined.

public void bouton_valide_ajout_texte(View v)

    {
        new_text_view.setText(((TextView) dialog.findViewById(R.id.edit_ajoute_texte)).getText());

        RelativeLayout rl_newtext_1 =  (RelativeLayout)findViewById(R.id.rl_newtext_1);

        rl_newtext_1.addView(new_text_view);*/

        TextView text_view = new TextView(this);
        text_view.setText(((TextView) dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());

        ListView liste_view_police = (ListView) dialog_ajoute_texte.findViewById(R.id.list_view_dialog_polices);
        text_view.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
        text_view.setTypeface(listePolices.get_typeface(position_item_police));
        text_view.setTextColor(Color.argb(255, 0, 0, 0));

        text_view.clearComposingText();

        container_calques.addView(text_view);

        Object[] tab_calque = new Object[5];
        tab_calque[0]="texte";
        tab_calque[1]=text_view;
        tab_calque[2]=12;
        tab_calque[3]=0;

        liste_calques.add(tab_calque);
        calque_selectionne=liste_calques.size()-1;
        text_view.setOnTouchListener(new TouchListener_calque(liste_calques.size()-1));

        dialog_ajoute_texte.hide();
    }

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

    xmlns:ebm="http://schemas.android.com/apk/res-auto"
    xmlns:sat="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="350dp"
        android:layout_gravity="center"
        android:id="@+id/rl_container_tshirt">

        <ImageView
            android:id="@+id/tshirt_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:src="@drawable/tee_shirt_blanc">

            </ImageView>

        <RelativeLayout
            android:id="@+id/container_calques"
            android:layout_width="120dp"
            android:layout_height="220dp"
            android:layout_marginLeft="88dp"
            android:layout_marginTop="85dp"

            >

        </RelativeLayout>

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layout_reglages_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"

        >

        <SeekBar
            android:id="@+id/seekbar_taille"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="10dp"
            android:layout_alignParentLeft="true"
            android:max="40"
            android:progress="20"

            />
        <SeekBar
            android:id="@+id/seekbar_rotation"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="50dp"
            android:layout_alignParentLeft="true"
            android:max="360"
            android:progress="180"
            />


        <Button
            android:textSize="10sp"

            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Supprimer"
            android:layout_alignParentRight="true"
            android:layout_marginRight="8dp"
            android:onClick="bouton_supprimer_calque"/>
        <Button
            android:textSize="10sp"

            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Couleur"
            android:layout_alignParentRight="true"
            android:layout_marginRight="8dp"
            android:layout_marginTop="40dp"
            android:onClick="bouton_choisir_couleur"/>

        <Button
            android:textSize="10sp"

            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Police"
            android:layout_alignParentRight="true"
            android:layout_marginRight="8dp"
            android:layout_marginTop="80dp"
            android:onClick="bouton_choisir_police"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        >
    <Button
        android:textSize="10sp"

        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:text="ajouter texte"
        android:id="@+id/ajouter_calque"
        android:onClick="bouton_ajoute_texte"/>

    <Button
        android:textSize="10sp"

        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:text="ajouter image"
        android:id="@+id/ajouter_image"
        android:onClick="bouton_ajoute_image"
        android:layout_alignParentRight="true"
        />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="enregistrer création dans galerie"
            android:id="@+id/enregistrer_creation"
            android:onClick="bouton_enregistrer_creation"
            android:layout_below="@+id/ajouter_calque"
            />
    </RelativeLayout>

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <android.view.ext.SatelliteMenu
            android:id="@+id/menu_flottant_gauche"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_margin="8dp"
            sat:satelliteDistance="170dp"
            sat:mainImage="@drawable/ic_launcher"
            sat:totalSpacingDegree="90"
            sat:closeOnClick="true"
            sat:expandDuration="200"

            />

    </FrameLayout>

</LinearLayout>

Solved

I replaced

text_view.setText(((TextView);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());

By

text_view.setText(((EditText);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText().toString());
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

The possible underline could by the ListView as it puts a divider between its items. Look at this answer to get rid of the divider

Community
  • 1
  • 1
Zaid Qureshi
  • 1,203
  • 1
  • 10
  • 15
  • The listview is not used, I don't know why I let it. I comment the listview declaration line and check for the result. – Olivier Racaniere Mar 03 '16 at 22:15
  • can you post your layout file? – Zaid Qureshi Mar 03 '16 at 22:21
  • I edited my post but it doesn't display nice on post – Olivier Racaniere Mar 03 '16 at 22:25
  • You can probably format that, but I dont see where you add the textview in XML – Zaid Qureshi Mar 03 '16 at 22:27
  • also does your container that you are adding text to have any dividers or borders – Zaid Qureshi Mar 03 '16 at 22:32
  • Ah ok, it's because I used a global variable for the relative layout where I add the TextView : public RelativeLayout container_calques; protected void onCreate(Bundle savedInstanceState) { ..... container_calques = (RelativeLayout) findViewById(R.id.container_calques); .... } – Olivier Racaniere Mar 03 '16 at 22:33
  • Not sure if that solved your problem, but where do you add your relative layout, does your relative layout have a border or its surroundings that may add that line – Zaid Qureshi Mar 03 '16 at 22:43
  • What do you mean by borders or surrounding ? There are no "colored borders", the relative layout have margins and limited width and height, so the textview can be only visible in this layout. – Olivier Racaniere Mar 03 '16 at 22:50
  • Text view doesnt have Line underline by default, so either its something surrounding the textview or you set it to underline – Zaid Qureshi Mar 04 '16 at 00:09
  • I think I found the problem : I was getting the text from EditText control, which I converted to TextView and then call getText(). What I did for correct : (EditText) dialog.....getText().toString() instead of classic getText() – Olivier Racaniere Mar 19 '16 at 15:15
0

Please make sure you don't have any inputType to your textview as follows

android:inputType="something"