2016-06-15 10 views
0

Ich verwende benutzerdefinierte EditText wie dieseEditText Cursor nicht sichtbar in android

public class DosisEdittextFont extends TextView { 
    public DosisEdittextFont(Context context) { 
     super(context); 
     init(context); 
    } 

    public DosisEdittextFont(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(context); 
    } 

    public DosisEdittextFont(Context context, AttributeSet attrs, 
     int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(context); 
    } 

    private void init(Context context) { 
     Typeface t = Typeface.createFromAsset(context.getAssets(), 
      "fonts/Dosis-Regular.otf"); 
     this.setTypeface(t); 
    } 
} 

Aber wegen dieser Cursor zeigt nicht in EditText. Wie setze ich den Cursor in benutzerdefinierte EditText?

Antwort

0

können Sie sich EditText statt Textview

+0

Sie mit einigen Code erklären oder Text –

+1

Lucas Nicoletti Sie sind right..thanks Beantwortungs ..its arbeiten .. – aj0822ArpitJoshi

+0

Keine Probleme Geck, froh, dass ich das Problem beim ersten Schuss gefunden: p –

0

Try This

public class CustomEditText extends EditText { 

    public CustomEditText(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     if(!isInEditMode()) 
     init(attrs); 
    } 

    public CustomEditText(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     if(!isInEditMode()) 
     init(attrs); 

    } 

    public CustomEditText(Context context) { 
     super(context); 
     if(!isInEditMode()) 
     init(null); 
    } 

    private void init(AttributeSet attrs) 
    { 
     if (attrs!=null) 
     { 
      TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomTextView); 
      String fontName = a.getString(R.styleable.CustomTextView_fontFamily); 

      if (fontName!=null) 
      { 
       Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/"+fontName); 
       setTypeface(myTypeface); 
      } 
      a.recycle(); 
     } 
    } 
} 

in Ihrem Layout verwenden

<CustomEditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/etEmailId" 
      android:hint="@string/email" 
      android:textColor="@color/input_text_color" 
      android:textColorHint="@color/input_text_color" 
      customfont:fontFamily="YOUR FONT NAME.ttf" 

      /> 
0
Reason for not appearance of cursor in edittext are many like your theme appearance  
i.e. theme style or edittext background and one is that you extending TextView, 
so try extending EditText in place of TextView as: 


import android.content.Context; 
import android.graphics.Typeface; 
import android.util.AttributeSet; 
import android.widget.EditText; 


public class CustomEditText extends EditText { 

private Context context; 
private AttributeSet attrs; 
private int defStyle; 

public CustomEditText(Context context) { 
    super(context); 
    this.context = context; 
    init(); 
} 

public CustomEditText(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    this.context = context; 
    this.attrs = attrs; 
    init(); 
} 

public CustomEditText(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    this.context = context; 
    this.attrs = attrs; 
    this.defStyle = defStyle; 
    init(); 
} 

private void init() { 
    Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/montserrat_bold.ttf"); 
    this.setTypeface(font); 
} 

@Override 
public void setTypeface(Typeface tf, int style) { 
    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/montserrat_bold.ttf"); 
    super.setTypeface(tf, style); 
} 

@Override 
public void setTypeface(Typeface tf) { 
    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/montserrat_bold.ttf"); 
    super.setTypeface(tf); 
} 
} 

and in you layout xml 

<com.example.CustomEditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/edittext" 
     android:hint="text" 
     android:textColor="#000000" 
     android:textColorHint="#000000"/> 




So, try replacing textview with edittext , if still not resolve, this 
occurs due to your activity theme or your edittext background