Issue
I have an EditText
box that has a custom drawable
background, but whenever you select the EditText
to input something the background disappears and makes the text impossible to read (it is the same color as the app background)
Here is what I am talking about:
The background just disappears and I am not sure why this is happening. This is my .xml
<EditText
android:id="@+id/enterCode"
android:layout_width="237sp"
android:layout_height="55sp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="8dp"
android:autofillHints="true"
android:background="@drawable/rect_yellow_border"
android:ems="10"
android:hint="Enter Game PIN"
android:inputType="text"
android:textAlignment="center"
android:textColor="@color/colorPrimary"
android:textColorHint="#40292929"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/products_toolbar"
app:layout_constraintVertical_bias="0.309" />
I have also tried to set the background in Java
but the issue is not fixed when I tried doing that either. Any help?
Here is my drawable
file. It is a bit unnecessary and weird because I just edited the code of one of my rounded shapes and made it into a square
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<stroke android:width="3dip" android:color="#ffc847" />
<gradient android:angle="-180" android:startColor="#ffffff" android:endColor="#ffffff" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<stroke android:width="3dip" android:color="#ffc847" />
<stroke android:width="3dip" android:color="#ffc847" />
<solid android:color="#ffc847"/>
<gradient android:angle="-45" android:startColor="#ffffff" android:endColor="#ffffff" />
</shape>
</item>
</selector>
In my Activity
all I have done to define this EditText
is this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_private_room_lobby);
final Button createPrivateGame = findViewById(R.id.createPrivateGame);
final Button joinPrivateRoom = findViewById(R.id.joinPrivateGame);
final EditText pinEntry = findViewById(R.id.enterCode);
joinPrivateRoom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pin = pinEntry.getText().toString().trim();
if(TextUtils.isEmpty(pin) || pin.length() > 6 || pin.length() < 6)
{
Toast.makeText(PrivateRoomLobby.this, "Please enter a 6 digit PIN to enter the room", Toast.LENGTH_LONG).show();
} else {
joinGame(pin);
}
}
});
Solution
A selector is used to defining view
component’s background color or background image by its various state. for more detail check this
you need to use the only shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dip" android:color="#ffc847" />
<solid android:color="#ffffff"/>
<!-- <gradient android:angle="-45" android:startColor="#ffffff" android:endColor="#ffffff" />-->
</shape>
Answered By - Adil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.