• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps I am having some problems with a custom TextView

Lampros_36

Lurker
Hi everyone,

I am creating a custom TextView on my project, in order to apply different fill and stroke characteristics on each TextView. I am overriding the onDraw method on each View and setting the layout xml file accordingly. Here is the xml file (customTxtView):

<gr.***.***.Guess.GuessQuestion.customTxtView
android:id="@+id/txtViewGuessQuestion"
android:layout_width="867dp"
android:layout_height="52dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:autoText="false"
android:freezesText="false"
android:gravity="center_horizontal|center_vertical"
android:includeFontPadding="false"
android:isScrollContainer="false"
android:keepScreenOn="false"
android:longClickable="false"
android:text="TEST"
android:textSize="40sp"
android:textStyle="bold"
android:shadowColor="#000"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="1.5"
app:barrierAllowsGoneWidgets="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.19" />

and the customView as defined programmatically:

//custom textview class
class customTxtView extends TextView {

public customTxtView(Context context, AttributeSet attrs) {
super(context, attrs);

}

//override the onDraw canvas methdo
protected void onDraw(Canvas pCanvas) {

//set the stroke color for the text
int strokeColor = Color.WHITE;
setTextColor(strokeColor);
getPaint().setStrokeWidth(5);
getPaint().setStyle(Paint.Style.STROKE);
super.onDraw(pCanvas);
//set the fill color for the text
int fillColor = Color.BLUE;
setTextColor(fillColor);
getPaint().setStrokeWidth(0);
getPaint().setStyle(Paint.Style.FILL);
super.onDraw(pCanvas);
}

}

While i am inflating the layout i am getting the error:

android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class gr.***.***.Guess.GuessQuestion.customTxtView

*Added_Info: Caused by: java.lang.ClassNotFoundException: Didn't find class "gr.***.aia_project.Guess.GuessQuestion.customTxtView" on path:


Can you help me to identify the cause of the issue?

Thank you in advance,
Lampros
 
Last edited:
Clue's in the error message :)
Line 9 of your XML file is incorrect syntax.

android:gravity="center_horizontal|center_vertical"
 
Clue's in the error message :)
Line 9 of your XML file is incorrect syntax.

android:gravity="center_horizontal|center_vertical"

Thanx for the answer. I didnot include the whole xml file, so line 9 is not the gravity attribute definition but the beginning of the customtextView (the first line of the xml file included here.
 
Back
Top Bottom