0

My application is working successfully in Android 2.x to 4.1.x

In Google TV emulator i am running my existing application.

Google TV is not support touch input, So user must use navigation flow like move left, move right, move top and move bottom.

But this control can not point on ImageButton control.

How can reach my pointer for operate ImageButton.?

XML Layout :

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >

    <TextView
        android:id="@+id/headingTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dip"
        android:gravity="center_horizontal"
        android:text="Kit - Device Registration"
        android:textSize="75sp" />

    <RelativeLayout
        android:id="@+id/kitDetailsRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/headingTextView"
        android:layout_centerInParent="true"
        android:layout_marginTop="100dp" >

        <TextView
            android:id="@+id/WebURLTextView"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:gravity="right"
            android:text="Web Url:"
            android:textSize="50dp" />

        <EditText
            android:id="@+id/WebURLEditText"
            style="@style/EditTextStyle"
            android:layout_width="700dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60dp"
            android:layout_marginTop="30dp"
            android:layout_toRightOf="@id/WebURLTextView"
            android:hint="Enter Web Url"
            android:text=""
            android:textSize="40dp" />

        <TextView
            android:id="@+id/KitNoTextView"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/WebURLTextView"
            android:layout_below="@id/WebURLEditText"
            android:layout_marginTop="5dp"
            android:gravity="right"
            android:text="KIT No:"
            android:textSize="50dp" />

        <EditText
            android:id="@+id/KitNoEditText"
            style="@style/EditTextStyle"
            android:layout_width="700dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/WebURLTextView"
            android:layout_marginLeft="60dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@id/KitNoTextView"
            android:hint="Enter KIT No"
            android:textSize="40dp" />

        <TextView
            android:id="@+id/UniqueIdTextView"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/WebURLTextView"
            android:layout_below="@id/KitNoEditText"
            android:layout_marginTop="5dp"
            android:gravity="right"
            android:text="Unique Id:"
            android:textSize="50dp" />

        <EditText
            android:id="@+id/UniqueIdEditText"
            android:layout_width="700dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/KitNoTextView"
            android:layout_marginLeft="60dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@id/UniqueIdTextView"
            android:editable="false"
            android:focusable="false"
            android:textSize="40dp" />

        <Button
            android:id="@+id/ih_comBtn"
            android:layout_width="wrap_content"
            android:layout_height="72dp"
            android:layout_above="@+id/KitNoTextView"
            android:layout_toRightOf="@+id/WebURLEditText"
            android:text="@string/lbl_host_name"
            android:textSize="35sp" />
    </RelativeLayout>

    <ImageView
        android:id="@+id/topSettingsIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="10dip"
        android:layout_marginTop="10dip"
        android:background="@drawable/streak_settings" />

    <RelativeLayout
        android:id="@+id/kitControlRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp" >

        <ImageButton
            android:id="@+id/quitBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@drawable/quit_button" />

        <ImageButton
            android:id="@+id/verifyBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/quitBtn"
            android:layout_marginRight="20dip"
            android:layout_toLeftOf="@id/quitBtn"
            android:background="@drawable/register_button" />

        <ImageButton
            android:id="@+id/clearBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/quitBtn"
            android:layout_marginLeft="20dip"
            android:layout_toRightOf="@id/quitBtn"
            android:background="@drawable/clear_button" />
    </RelativeLayout>

</RelativeLayout>

Java File Code :

 import android.os.Bundle;
//Other Imports

    public class <classs Name> extends Activity {
        EditText webUrlEditTextObj;
        EditText uniqueIdEditTextObj;
        /**
         * Refers to Register image button
         */
        private ImageButton registerBtnObj;
        /**
         * Refers to Quit image button
         */
        private ImageButton quitBtnObj;
        /**
         * Refers to Clear image button
         */
        private ImageButton clearBtnObj;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);

            setContentView(R.layout.<XML file Name>);

            //...
            registerBtnObj = (ImageButton) findViewById(R.id.verifyBtn);
            quitBtnObj = (ImageButton) findViewById(R.id.quitBtn);
            clearBtnObj = (ImageButton) findViewById(R.id.clearBtn);

            verifyBtnObj.setOnClickListener(verifyListener);
            quitBtnObj.setOnClickListener(quitListener);
            clearBtnObj.setOnClickListener(clearListener);

            //...
        }

    /**
     * Listener for Register button click.
     */
    private OnClickListener verifyListener = new OnClickListener() {

        public void onClick(View v) {
            /**
             * Block of code
             */
        }
    };

    /**
     * Listener for Quit button click.
     */
    private OnClickListener quitListener = new OnClickListener() {

        public void onClick(View v) {
            /**
             * Block of code
             */
        }
    };

    /**
     * Listener for Clear button click.
     */
    private OnClickListener clearListener = new OnClickListener() {

        public void onClick(View v) {
            /**
             * Block of code
             */
        }
    };  
}
ethrbunny
  • 10,379
  • 9
  • 69
  • 131
Palak
  • 2,165
  • 2
  • 21
  • 31
  • post some code here...... – Piyush Aug 24 '13 at 09:25
  • I put XML file and Java code above. – Palak Aug 24 '13 at 11:39
  • In android "ImageButton"has default propertie android:focusable="true" but I seen that you might be check that your background selector for "ImageButton" should set under the [ state_focused="true"]. if you have "ImageView" then you need to set the properties [ android:focusable="true" ] – Bhavdip Sagar Sep 27 '13 at 10:41

1 Answers1

0

Make sure your ImageButtons are marked as focusable. You'll also want to make sure you set the nextFocus* related attributes as well. The following is from my project, Serenity for Android which uses ImageButtons on the OSD when playing a video.

   <ImageButton
        android:id="@+id/osd_rewind_control"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:focusable="true"
        android:nextFocusRight="@+id/mediacontroller_play_pause"
        android:nextFocusUp="@+id/mediacontroller_seekbar"
        android:scaleType="fitXY"
        style="@android:style/MediaButton.Rew"
        android:src="@drawable/skipback_selector"
        tools:ignore="ContentDescription" />

Again make sure you set the android:focusable to true. All source code for my app is available to look at as well.

https://github.com/NineWorlds/serenity-android/blob/master/serenity-app/res/layout-large/serenity_media_controller.xml

kingargyle
  • 1,239
  • 10
  • 15