Reputation: 13
I have a problem with the app (android studio, java).
I want the textview to remain visible at all times. Any tips? <3
learnButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
learnButton.setElevation(1);
return false;
}
});
<Button
android:id="@+id/buttonLearn"
android:layout_width="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_height="100dp"
android:background="@drawable/style_bg_light"
android:layout_marginTop="125dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/textViewLearn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:fontFamily="@font/dosis"
android:text="Button Continue"
android:elevation="2dp"
android:layout_marginStart="12dp"
android:layout_marginTop="5dp"
android:textColor="@color/black"
android:layout_alignTop="@+id/buttonLearn"
android:layout_alignStart="@+id/buttonLearn"/>
Upvotes: 1
Views: 200
Reputation: 3313
If you want the best practice, you need either to style the button itself or to style the text and put the click listener on the TextView
instead of the Button
for example:
<TextView
android:id="@+id/learn"
android:width="200pd"
android:height="48dp"
android:background="@drawable/button_bg"
android:gravity="center"
android:textColor="@color/white"
android:text="Click To Learn" />
And the file button_bg.xml to be added to the drawable folder, will contain:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="@color/lightGreyText">
<item android:drawable="@drawable/static_button_bg" />
</ripple>
</item>
</layer-list>
The file button_bg.xml handles the ripple effect on click, and the file static_button_bg.xml contains the style of the button, and it is:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#66EFEFF4" />
<corners android:radius="8dp" />
</shape>
Upvotes: 1