Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I add a clickable button to a textview that is clickable currently
    primarykey
    data
    text
    <p>New to android trying to figure something out, any help appreciated.I have a textview which is currently clickable. I just need to put a clickable button background to it. This is my xml file: mainscreen.xml under layout</p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@android:drawable/divider_horizontal" android:orientation="vertical" android:showDividers="middle" &gt; &lt;TextView android:id="@+id/mainscreen_option" style="@style/TextView.MainscreenItem" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginBottom="1dp" android:clickable="true" android:onClick="onMainscreenClicked" android:text="@string/nav_option" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the selector class code where i have defined the button is under drawable folder : bg_button.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_focused="true" android:drawable="@drawable/menu_btn_active"/&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/menu_btn_active" /&gt; &lt;item android:drawable="@drawable/menu_btn" /&gt; &lt;/selector&gt; </code></pre> <p>and the corresponding javacode for the textview is : mainscreennav.java</p> <pre><code>private void highlightMenuItem(){ TextView highlightedTextView = null; final String activeFragmentTitle = getArguments().getString(ACTIVE_MENU_ITEM); final Resources resources = Application.getAppResources(); if (resources.getString(R.string.nav_option_mainscreen).equals(FragmentTitle)) { highlightedTextView = (TextView) getView().findViewById(R.id.nav_option_mainscreen); } highlightedTextView.setTextColor(getResources().getColor(R.color.dark_orange)); } } </code></pre> <p>Can anyone guide me as to how I can convert this textview into a button such that both are clickable together and i can set the text margin in the button from left as certain dp's. Thanks in advance! Justin</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload