标签: d-pad

D'pad在模拟器中被禁用

我正在使用android sdk 4.0.3,我已经创建了它的模拟器.现在我有一个问题,模拟器显示已禁用DPAD按钮.我已设置硬件键盘,并在配置中显示带按钮选项的外观.

所以我只想在模拟器上启用Dpad按钮

eclipse android android-virtual-device android-emulator d-pad

25
推荐指数
4
解决办法
3万
查看次数

如何支持RecyclerView的dpad控件

我目前正在尝试将Android移动应用移植到Android TV.我有一个似乎在我的Android TV应用程序中正确显示的RecyclerView.我正在使用linearLayout作为我的RecyclerView.但我似乎无法使用dpad控件在RecyclerView中导航.

有任何想法吗?

这是有关的xml:

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RecyclerView"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="@color/nav_bg"
    android:scrollbars="vertical"
    tools:showIn="@layout/activity_content" />
Run Code Online (Sandbox Code Playgroud)

android d-pad android-tv android-recyclerview

10
推荐指数
2
解决办法
3938
查看次数

Android:有没有办法模拟D-Pad事件(API 10)?

问题很简单.我必须模拟dpad事件(UP,DOWN,RIGHT,LEFT,CENTER),以便在我的GUI中导航,其中包含许多按钮和其他元素.使用模拟器D-Pad,我可以在没有行代码的情况下导航此GUI.但是我该如何以编程方式执行此操作?

我尝试了很多但没有成功:

  • KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_DPAD_LEFT); View.dispatchKeyEvent(event); 没有任何事情发生(焦点应该将一个元素移动到右边)

  • 我也阅读了很多关于windowManager.injectKeyEvent的内容,但发现没有任何效果.

  • 而Instrumentation可以帮助模拟关键事件,但更多用于测试,而不是用于应用程序本身.

我认为有一个解决方案,因为对讲可以模拟物理D-Pad(http://code.google.com/p/eyes-free/source/browse/trunk/ime/latinime/src/com/googlecode/eyesfree /inputmethod/latin/LatinIME.java)

simulation android keyevent d-pad

7
推荐指数
1
解决办法
2937
查看次数

Android TV将焦点转移到RecyclerViews之间

我正在使用以下布局构建Android TV应用: 在此输入图像描述

左侧和右侧的两个列表都是带有垂直LinearLayoutManagers的RecyclerViews,Header视图是静态的.使用D-PAD导航在一个列表中工作正常,但是当从一个列表切换到另一个列表时,存在问题.焦点从list1的项目5移动到list2'项目5.当列表2短的时间少于5项时,它就会失去焦点.

我希望保存最后一个聚焦项目索引,并且当用户导航list1-list2-list1时,具有该索引的项目再次获得焦点并且还防止视图失去焦点.这有什么好的解决方案吗?

所需行为:用户导航到列表顶部并按"向上" - 焦点保持原样,没有任何反应.用户导航到列表的底部并按下"向下" - 焦点停留在原来的位置,没有任何反应.用户从list1导航到list2 - 之前在list2中具有焦点的项目,如果之前没有聚焦,则获得焦点或item0获得焦点.

主要布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    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"
    >

    <ImageView
        android:id="@+id/iv_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="false"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="27dp"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="48dp"
        android:layout_marginTop="27dp"
        android:orientation="horizontal"
        >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:orientation="horizontal"
                >

                <ImageView
                    android:id="@+id/iv_poster"
                    android:layout_width="@dimen/episodes_list_item_height"
                    android:layout_height="@dimen/episodes_list_image_width"
                    />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    >

                    <TextView
                        android:id="@+id/tv_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />

                    <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        >

                        <TextView
                            android:id="@+id/tv_release_date"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            />

                        <TextView
                            android:id="@+id/tv_rating"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"
                            android:drawableLeft="@drawable/ic_star_white_24dp" …
Run Code Online (Sandbox Code Playgroud)

focus d-pad android-tv android-recyclerview

6
推荐指数
1
解决办法
2936
查看次数

如何获得EditText的焦点并使用Android TV中的D-pad进行导航

我正在使用EditText&PopupWindow由于一些GUI要求创建基于建议的搜索功能.搜索和建议工作正常,但我无法浏览搜索EditText和列出PopupWindow通过Dpad的项目.

以下是我整个屏幕的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
    android:id="@+id/center_baseline"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_centerInParent="true" />

<View
    android:id="@+id/top_baseline"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_above="@+id/center_baseline"
    android:layout_marginBottom="50dp" />

<View
    android:id="@+id/bottom_baseline"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_below="@+id/center_baseline"
    android:layout_marginTop="45dp" />

<RelativeLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignBottom="@id/bottom_baseline"
    android:layout_alignParentTop="true"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true">

    <ImageView
        android:id="@+id/top_shelf_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="@dimen/top_shelf_image_alpha"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY" />

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/home_screen_top_bar_height"
        android:layout_alignParentTop="true"
        android:alpha="@dimen/home_screen_top_bar_alpha"
        android:background="@color/black" />

    <ImageView
        android:id="@+id/app_logo"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/home_screen_logo_height"
        android:layout_marginLeft="20dp"
        android:contentDescription="@string/app_name"
        android:gravity="center"
        android:padding="5dp"
        android:src="@drawable/ic_app_logo" />

    <EditText
        android:id="@+id/team_search_bar"
        android:layout_width="@dimen/home_screen_search_bar_width"
        android:layout_height="@dimen/home_screen_logo_height"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp"
        android:hint="@string/lb_search_bar_hint"
        android:imeOptions="actionSearch" …
Run Code Online (Sandbox Code Playgroud)

search android android-edittext d-pad android-tv

5
推荐指数
0
解决办法
789
查看次数

使用 Android TV 应用程序的遥控器

我正在开发一个用于电视的 Android 应用程序,当我尝试在真正的 Android TV 中测试它时,我无法使用遥控器上、下、左、右按钮导航到任何按钮或任何内容。

我搜索过它,发现我必须使用(启用方向键导航),但我不知道如何使用它,我没有找到任何代码或教程我的应用程序非常简单。它使动态布局彼此并排,每个布局只有一个按钮和一个回收视图。

android google-tv d-pad android-tv

5
推荐指数
1
解决办法
6649
查看次数

潜在的 Glide 错误 - 在 Android TV 上使用 Dpad 快速滚动时 RecyclerView 项目失去焦点

我正在尝试为 Android TV 制作一个基本的相册应用程序。

将 recyclerview 与 glide 一起使用。

问题:当按下 dpad 向下按钮缓慢地一项一项滚动时,recyclerview 项目如预期一样准确地获得焦点。但是,当按住 dpad 向下按钮时,在快速滚动期间,recyclerview 项目很容易失去焦点,并且焦点会移动到 recyclerview 外部的任何可聚焦视图(在本例中为编辑文本),并且无法滚动,直到手动将焦点移动到 recyclerview 内部再次。

尝试的补救措施: 1. 如果我完全禁用 Glide 加载图像(在 onBindViewHolder() 内部),焦点永远不会丢失,无论滚动速度有多快,它总是按预期工作。由于需要查看图像,因此该补救措施没有用。2. 如果通过重写 Activity.onKeyDown 方法来限制快速滚动,以忽略所有按键输入,除非自上次按下按键以来已过去 300 毫秒,否则它会起作用。同样,这感觉非常hacky并且完全禁用快速滚动是绝对要求。

请注意,我已经阅读了 stackoverflow 上的相关 QA。这表明这是 Android 支持库 LayoutManager 代码中的一个错误,但这里的情况并非如此,因为没有 glide 它可以正常工作。

如何重现:创建一个像 ListFragment 这样的片段(代码如下),并通过按住向下 Dpad 按钮尝试快速滚动,您将看到 editText 不断获得焦点。

代码:ListFragment.java

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import …
Run Code Online (Sandbox Code Playgroud)

android d-pad android-tv android-recyclerview android-glide

5
推荐指数
1
解决办法
1427
查看次数

Android TV 方向键的 KeyEvent

在活动中,我的工具栏中有 TabLayout、ViewPager 和菜单按钮(汉堡包)。

使用键盘上的箭头,默认情况下我可以从选项卡移动到查看寻呼机项目,没有任何问题,但我无法将焦点放在工具栏菜单按钮上。

首先,当按下 KeyEvent.KEYCODE_DPAD_UP 时我无法收听,我想知道为什么。

我的代码:

viewPager = findViewById(R.id.viewpager);
viewPager.setAdapter(adapter);
tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

tabLayout.setOnKeyListener(new View.OnKeyListener() {
    @Override
    public boolean onKey(View view, int i, KeyEvent keyEvent) {
        if ((keyEvent.getAction() == KeyEvent.ACTION_UP) && (i == KeyEvent.KEYCODE_DPAD_UP)) {
            toolbar.setFocusable(true);
            toolbar.setFocusableInTouchMode(true);
            tabLayout.setNextFocusUpId(R.id.toolbar);
            Log.d(TAG, "KEYCODE_DPAD_UP");
            tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
            tabLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        }
        return false;
    }
});
Run Code Online (Sandbox Code Playgroud)

我的 if 语句有什么问题?

android if-statement listener d-pad android-tv

4
推荐指数
1
解决办法
4642
查看次数

Flutter 如何制作一个可选择/可聚焦的小部件

我正在创建一个 Android 电视应用程序。我花了很长时间试图弄清楚为什么当我单击遥控器上的向上和向下箭头按钮时,它似乎没有执行任何操作,并且没有选择任何列表项。

最终我发现,如果我使用列表中的提升按钮或其他可聚焦的小部件,我可以使用箭头键,它会工作得很好。以前我使用的是包裹在手势检测器中的卡片小部件。

所以我想知道带有手势检测器的按钮和卡片之间的区别是什么,阻止箭头键选择项目。我怀疑这是焦点。

这就是我使用的不允许遥控器上的向上、向下键选择它的方法:

GestureDetector(
    child: Card(
      color: color,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(15.0),
      ),
      elevation: 10,
      child: SizedBox(
          width: (width / numberOfCards) - padding * (numberOfCards - 1),
          height: (height / 2) - padding * 2,
          child: Center(child: Text(cardTitle, style: Theme.of(context).textTheme.bodyText1?.copyWith(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),))),
    ),
    onTap: () => onCardTap(),
  ),
Run Code Online (Sandbox Code Playgroud)

这是我替换它的按钮,然后使上下键和选择起作用:

ElevatedButton(
                  onPressed: () {},
                  child: Text('Test 1', style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white, fontSize: 18, fontWeight: FontWeight.normal)),
                  style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all(Colors.grey.withOpacity(0.3)),
                      minimumSize: MaterialStateProperty.all(Size(60, 60)),
                      elevation: MaterialStateProperty.all(10),
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: …
Run Code Online (Sandbox Code Playgroud)

focus d-pad android-tv flutter

3
推荐指数
1
解决办法
4890
查看次数

Recyclerview和D-pad导航

我正在开发一个需要使用D-pad导航的应用程序RecyclerView.我的问题是虽然我设置android:focusable=trueitems.xml(news_items),但它似乎不起作用.

我的问题是:我应该如何实现D-pad导航RecyclerView

RecyclerView是以下布局内:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

         />
    <TextView
        android:id="@+id/emptyView"
        android:visibility="gone"
        tools:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=":( \n No news available"
        android:textSize="@dimen/fsn_emty_text"
        android:layout_gravity="center_vertical"
        android:gravity="center_horizontal"
        android:paddingEnd="@dimen/activity_horizontal_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingStart="@dimen/activity_horizontal_margin"
        />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

news_items.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/news_ripple"
    android:clickable="true"
    android:focusable="true"
    android:orientation="vertical"

    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.15"
                android:background="?attr/colorAccent"

                />


            <LinearLayout

                android:layout_width="0dp" …
Run Code Online (Sandbox Code Playgroud)

android d-pad android-recyclerview

2
推荐指数
1
解决办法
2849
查看次数