Selection button does not work in Android TV - android

I do not understand why this layoutcan not be selected anything in android tv.
it's not possible select any button or whiget, or insert text.
Please help me, and if you can and tell the reason.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp" />
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:src="#android:drawable/ic_menu_share"
app:elevation="6dp"
app:borderWidth="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />

Firstly, you have to keep focus of any one of items (i.e. Button, TextView, etc.) as below. And also, you have to apply it's nextFocusDown, nextFocusLeft, nextFocusRight & nextFocusUp properties. So it will fire it's releveant event when you click TV remote navigation buttons.
Add request focus to your edit text like this,
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp"
android:nextFocusDown="#+id/bSendUrl">
<requestFocus></requestFocus>
</EditText>
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
</Button>
And after that, you can add more properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus next item.

Related

Kotlin can't click on empty EditText

I am creating a profile activity and each row contain on one side a textview for the information about the row for exemple : Name, on the other side i have an EditText to change the information when we click on validate. here is the xml for each row :
<FrameLayout
android:id="#+id/first_name_row"
android:layout_marginBottom="#dimen/profile_row_bottom_margin"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/small_item_list_height"
android:paddingEnd="#dimen/default_padding"
android:paddingLeft="#dimen/default_padding"
android:paddingRight="#dimen/default_padding"
android:paddingStart="#dimen/default_padding">
<TextView
android:includeFontPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:text="#string/acct_first_name"
android:textSize="#dimen/profile_row_text_size" />
<EditText
android:id="#+id/acc_name_first"
android:includeFontPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:background="#null"
android:text="#string/acct_first_name"
android:enabled="false"
android:focusable="false"
android:cursorVisible="false"
android:textSize="#dimen/profile_row_text_size" />
</RelativeLayout>
</FrameLayout>
The problem is that I added android:background="#null" because I don't want the bar under the field. but when I do that I delete all character from the field, it's become empty and if I change to focus on another field, I can't click on the empty field.
Here you have the image, the field Nom is selected but we see that the field prename is empty so I can't select it. also, the field email work because I didn't put backgound = null but I don't want the bar under it.
Is there a way to have a Textedit that doesn't have a bar under it but can still be clickable is it's empty?
EditText has android:layout_width="wrap_content" once you remove all the char with becomes zero, next time even if you enable it you cannot click it. Use attribute android:minEms="1".
From my point of view it will be better to just add some minimum width to your edit text:
<EditText
android:id="#+id/acc_name_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:background="#null"
android:cursorVisible="false"
android:enabled="false"
android:focusable="false"
android:includeFontPadding="false"
android:minWidth="50dp"
android:text="#string/acct_first_name"
android:textSize="#dimen/profile_row_text_size" />

Aligning multiple checkboxes vertically

I try to align four checkboxes but one is not in the center of the other. If I shorten the text it fits but if its longer it looks like in the screenshot. The problem is it will be in different languages so the text size can be different. Also if I remove the scale it fits perfect but I need this bigger checkboxes
This is my code:
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:text="#string/unmounted"
android:textColor="#color/textBlack"
android:layout_below="#+id/abc"
android:layout_toEndOf="#+id/imageView6"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_not_working"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_defective"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_tie"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
Here is the exact solution for your problem, the thing which you are actually trying to achieve is the bigger checkbox view (corresponding to its text which is as big as the checkbox view, obviously) with proper alignment of all the views in the series, something like this:
Your desired UI.
But the thing you are doing wrong is that you are using the scaleX and scaleY attributes for achieving your desired UI that distorts your view as these two attributes scale the complete view i.e. the squared checkbox view with its text/label in the X and Y directions respectively (together with the text/label of the checkbox), so there is a dependency on the text as well (which is distorting your view).
So, the below code will solve your problem:
(In this I have taken the squared checkbox view as separate and beside it I have placed a textview in which I have written the text which corresponds to the text/label of that checkbox to complete the UI). Thereby using two views (i.e. the CheckBox and the TextView beside it) instead of using a single compound view (i.e. the CheckBox).
Note: In the solution given below, the CheckBox is a compound view but I haven't used it in the
same manner.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/some_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp" />
<!--android:text="Unmounted"-->
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_below="#+id/some_view"
android:layout_alignStart="#+id/some_view"
android:focusable="false" />
<TextView
android:id="#+id/tv_for_cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb1"
android:layout_alignTop="#+id/cb1"
android:layout_alignBottom="#+id/cb1"
android:layout_marginStart="40dp"
android:text="Unmounted"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Not Working"-->
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb2"
android:layout_alignTop="#+id/cb2"
android:layout_alignBottom="#+id/cb2"
android:layout_marginStart="40dp"
android:text="Problem Not Working"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Defective"-->
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb3"
android:layout_alignTop="#+id/cb3"
android:layout_alignBottom="#+id/cb3"
android:layout_marginStart="40dp"
android:text="Problem Cable Defective"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Tie"-->
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb4"
android:layout_alignTop="#+id/cb4"
android:layout_alignBottom="#+id/cb4"
android:layout_marginStart="40dp"
android:text="Problem Cable Tie"
android:textColor="#android:color/black"
android:textSize="24sp" />
</RelativeLayout>
And the other way out to your mentioned problem would be to create custom drawables for the checkbox and then handle them using a state list drawable as for the checkbox to be shown differently in different states as when it is unchecked, checked etc.
This link would help you if you are interested in doing it in this manner or way and would be great if you want to customize your checkbox's view.
Creating custom checkbox using selectors and shapes.
For further help in this context refer:
Android: How to change CheckBox size?

how to rearrange my textview in my relativelayout?

Here's my layout screenshot:
How can I arrange all these TextView for them to have a good format (heading being Taking responsibility (means being aware)..) alignment etc.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Menu"
android:background="#android:color/holo_blue_bright"
>
<TextView
android:text="*Follow safety guide for moving around the town and between towns."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="51dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_marginBottom="23dp"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25" />
<TextView
android:text="*keep this briefing pack in an accessible place, and the emergency numbers in your mobile phone memory"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_marginBottom="46dp" />
<TextView
android:gravity="center"
android:textColor="#000"
android:textSize="15dp"
android:text="Taking resposibility(means being aware)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView22"
android:layout_marginTop="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Avoid moving around town by yourself and always make others aware of your location."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/textView25"
android:layout_marginTop="76dp"
android:layout_below="#+id/textView22"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Share any security information that might have implications for Ballloon Ventures to the Country Manager or pc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView24"
android:gravity="left"
android:layout_below="#+id/textView26"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:text="*If using host home accommondation,check that it is secure.if it is not,tell the Programme Coordinator"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_marginTop="14dp"
android:layout_below="#+id/textView24"
android:layout_alignRight="#+id/textView25"
android:layout_alignEnd="#+id/textView25" />
<TextView
android:text="*Report all incidents to your Programmer Cordinator."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView26"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
</RelativeLayout>
Because if I drag one TextView it affecting all other TextView.
As #GabeSechan said, you need to learn what android:layout_xxx properties in RelativeLayout means.
When you moving a View in RelativeLayout via Layout Editor, you need to consider some of the following properties in your layout:
android:layout_above="#+id/textView25"
android:layout_below="#+id/textView24"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView25" means that you want the View above textView25 view.
android:layout_below="#+id/textView24" means that you want the View below textView25 View.
The following properties means that you want the view to the right side of TextView25 View:
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
The following properties means that you want the view to align with the left side of the parent layout:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
If you want to edit views position in a RelativeLayout, please don't depends with drag and drop via Layout Editor. You better do it manually except you want to have a headache later. Use Layout Editor to view the design result.
Design with a paper or imagination first, then code it after that.
Try to learn it from:
Relative Layout
Constructing View Layouts
The best practice for doing that would be to open a splitview between your code and design views and then editing the code to place the text in the correct location, using attributes such as padding, margin, aligning, below, above, etc. refer to this guide for positioning stuff in relative layout and combine it with other formatting attributes such as margin and padding.

Android Studio XML - How to get imageview in front of button?

The question is quite simple. How do I get this imageview below to be visible in front of the button below?
I am looking for an XML answer, not a Java answer. Seeing java (I think) will not change anything in the preview screen while working on the xml file.
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/iconfb"
android:layout_marginTop="90dp"
android:layout_marginLeft="12.5pt"
android:id="#+id/iconfb"
/>
<Button
android:layout_width="300dp"
android:layout_height="40dp"
android:text="Sign in with facebook"
android:onClick="invokefb"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#color/tmfacebook"
android:layout_marginTop="-20dp"
android:layout_marginLeft="12.5pt"
android:id="#+id/fblogin"
"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="10dp"
android:drawableLeft="#drawable/fb"
android:text="Facebook"/>

How to invisible line in list view for android Honey comb

I m creating an app in that app i want to invisible this Mr. bla bla two line when i clicked on chat image.
any suggestion will be appriciate.
thanks in advance.
this is my xml file.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_frag_list_message_layout"
android:background="#EBEBEB"
android:layout_marginBottom="10dp"
android:descendantFocusability ="blocksDescendants"
android:layout_marginTop="10dp"
android:layout_below="#+id/task_list_text"
android:layout_marginLeft="80dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion1"
android:text="Mr. Test : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text1"
android:text="A send you a data file kindly get it."
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_toRightOf="#+id/task_list_chat_persion1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion2"
android:text="Mr. me : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text2"
android:text="I got the data file and i have some doubt in them"
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:layout_toRightOf="#+id/task_list_chat_persion2"
/>
</RelativeLayout>
this two lines are ij relative latout.
I think you want this ...
just need to add onClick() event on chat image and then on clicking set visibility of TextView to invisible by code.
TextView _text= (TextView)findViewById(R.id.task_list_chat_text);
_text.setVisibility(TextView.INVISIBLE);
When you click on chat button in the list view you should setTest="" blank for both remove it.
It may be solution of this problem.

Categories

Resources