2017-08-04 24 views
1

要使用我的字体,我用服装的TextView用下面的代码:的onClick自定义文本视图不工作在Android版本低于5

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

public class CustomTextView extends TextView { 
    public CustomTextView(Context context) { 
     super(context); 
     setFont(); 
    } 
    public CustomTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     setFont(); 
    } 
    public CustomTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     setFont(); 
    } 

    private void setFont() { 
     Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/BNazanin.ttf"); 
     setTypeface(font, Typeface.NORMAL); 
    } 


} 

和布局:

<... .CustomTextView 
     ... 
     android:onClick="loadongallery" 
     /> 

和活动:

public void loadongallery(View v){ 
... 
} 

但是通过在小于5的Android版本上点击它,没有任何反应。 我需要字体和点击,请帮助我。

+0

如果您在XML加什么属性点击? –

+0

给你添加** loadongallery **方法代码。 –

+0

我使用这种方法,公共无效loadongallery(查看v){...} –

回答

1

多了一个属性添加到TextView的以xml:

android:clickable="true" 
+0

非常感谢,我的问题解决了。 –

相关问题