是否可以在leanback 展示应用程序的自定义标题视图中使用多个 SearchOrb 按钮或其他可聚焦按钮?问题是我只能聚焦一个按钮...
更新:
我做了什么:
有自定义标题视图类,其中包含搜索球、标题文本视图、自定义球和模拟时钟。
问题是当我尝试聚焦搜索球体时,焦点转到自定义球体......仅此而已。仅专注于自定义球体。
单击侦听器以设置主搜索球体。我不知道问题出在哪里。如果需要,我可以按需发布其他代码。
感谢您的帮助!
标题视图.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.olegmart.smart.base.CustomTitleView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/browse_title_group"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
自定义标题视图.java:
package com.olegmart.smart.base;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v17.leanback.widget.SearchOrbView;
import android.support.v17.leanback.widget.TitleViewAdapter;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ImageView;
import com.olegmart.smart.R;
public class CustomTitleView extends RelativeLayout implements TitleViewAdapter.Provider {
private final TextView mTitleView;
private final View mAnalogClockView;
private final View mGridOrbView;
private final View mSearchOrbView;
private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
@Override
public View getSearchAffordanceView() {
return mSearchOrbView;
}
@Override
public void setTitle(CharSequence titleText) {
CustomTitleView.this.setTitle(titleText);
}
@Override
public void setBadgeDrawable(Drawable drawable) {
//CustomTitleView.this.setBadgeDrawable(drawable);
}
@Override
public void updateComponentsVisibility(int flags) {
/*if ((flags & BRANDING_VIEW_VISIBLE) == BRANDING_VIEW_VISIBLE) {
updateBadgeVisibility(true);
} else {
mAnalogClockView.setVisibility(View.GONE);
mTitleView.setVisibility(View.GONE);
}*/
int visibility = (flags & SEARCH_VIEW_VISIBLE) == SEARCH_VIEW_VISIBLE
? View.VISIBLE : View.INVISIBLE;
mSearchOrbView.setVisibility(visibility);
}
private void updateBadgeVisibility(boolean visible) {
if (visible) {
mAnalogClockView.setVisibility(View.VISIBLE);
mGridOrbView.setVisibility(View.VISIBLE);
mTitleView.setVisibility(View.VISIBLE);
} else {
mAnalogClockView.setVisibility(View.GONE);
mGridOrbView.setVisibility(View.GONE);
mTitleView.setVisibility(View.GONE);
}
}
};
public CustomTitleView(Context context) {
this(context, null);
}
public CustomTitleView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomTitleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
View root = LayoutInflater.from(context).inflate(R.layout.custom_titleview, this);
mTitleView = (TextView) root.findViewById(R.id.title_tv);
mAnalogClockView = root.findViewById(R.id.clock);
mGridOrbView = root.findViewById(R.id.grid_orb);
mSearchOrbView = root.findViewById(R.id.search_orb);
}
public void setTitle(CharSequence title) {
if (title != null) {
mTitleView.setText(title);
mTitleView.setVisibility(View.VISIBLE);
mGridOrbView.setVisibility(View.VISIBLE);
mAnalogClockView.setVisibility(View.VISIBLE);
}
}
public void setBadgeDrawable(Drawable drawable) {
if (drawable != null) {
mTitleView.setVisibility(View.GONE);
mGridOrbView.setVisibility(View.VISIBLE);
mAnalogClockView.setVisibility(View.VISIBLE);
}
}
@Override
public TitleViewAdapter getTitleViewAdapter() {
return mTitleViewAdapter;
}
}
custom_titleview.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v17.leanback.widget.SearchOrbView
android:id="@+id/search_orb"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:transitionGroup="true"
android:layout_gravity="center_vertical|start"
android:layout_marginTop="8dp"
android:paddingStart="48dp"
android:focusable="true"
android:nextFocusRight="@+id/grid_orb"
/>
<AnalogClock
android:id="@+id/clock"
android:layout_width="80dp"
android:layout_height="80dp"
android:padding="6dp"
android:layout_alignParentEnd="true"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="24dp" />
<android.support.v17.leanback.widget.SearchOrbView
android:id="@+id/grid_orb"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/clock"
android:nextFocusLeft="@+id/search_orb"
android:focusable="true"
/>
<TextView
android:id="@+id/title_tv"
android:textAppearance="@android:style/TextAppearance.Large"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/grid_orb" />
</merge>