我想禁用点击/点按map markers.我知道你可以disable default behavior通过设置一个空map.setOnMarkerClickListener并返回true; 但是,这仍然会点击标记.我想把点击传递到onMapClickListener.
在我的应用程序中,点击地图会移动一个标记,如果您在标记已经靠近的位置点击,它只会认为您正在点击标记!你会认为有一种Marker.setClickable方法,但没有.
我有一个带有CardViews的RecyclerView.我希望每个CardView都有自己的YouTubePlayerFragment.即使它们不能同时处于活动状态,我甚至无法在任何CardView中实例化YouTubePlayerFragment,而是在RecyclerView中实现第一个.当点击卡上应该设置YouTubePlayerFragment的按钮时,它总是在第一张卡上设置,即使我点击了第二张卡.我正在尝试做什么?
以下是代码的相关部分:
CardView XML中片段的持有者:(直接在xml中使用片段给出了二进制XML异常,可能是由于片段中某个片段内的片段)
<FrameLayout
android:id="@+id/youtube_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/layout_video_thumbnail"
android:layout_alignStart="@+id/layout_video_thumbnail"
android:layout_alignRight="@+id/layout_video_thumbnail"
android:layout_alignEnd="@+id/layout_video_thumbnail"
android:visibility="visible"/>
Run Code Online (Sandbox Code Playgroud)
ViewHolder:
public class VideoViewHolder extends RecyclerView.ViewHolder {
protected FrameLayout containerYouTubePlayer;
protected TextView textViewTitle;
protected ImageView imageViewThumbNail;
protected Button buttonPreview, buttonSet;
protected Context activityContext;
public VideoViewHolder(Context activityContext, View itemView) {
super(itemView);
this.activityContext = activityContext;
containerYouTubePlayer = (FrameLayout) itemView.findViewById(R.id.youtube_holder);
textViewTitle = (TextView) itemView.findViewById(R.id.textView_title);
imageViewThumbNail = (ImageView) itemView.findViewById(R.id.imageView_video_thumbnail);
buttonPreview = (Button) itemView.findViewById(R.id.button_preview);
buttonSet = (Button) itemView.findViewById(R.id.button_set);
}
}
Run Code Online (Sandbox Code Playgroud)
RecyclerView适配器:
public class VideoCardAdapter extends RecyclerView.Adapter<VideoViewHolder> {
private static final …Run Code Online (Sandbox Code Playgroud) 我正在使用Android中的Google Maps V2在mapFragment中绘制几个圆圈.一切都是V1的桃子,但在切换后,我的圆圈的填充颜色并不总是被绘制.
例如,我打开地图,圆圈在那里并填充,但如果我缩放几次填充颜色消失.我缩小了它,它仍然消失了(或者它可能会重新出现).我无法确定哪种行为导致它消失,有时它甚至没有开始和缩放导致它出现.
这是我的一个圈子的一些代码:
private void addAccuracyCircle() {
accuracyCircle = map.addCircle(new CircleOptions()
.center(LocationFinder.getActualPoint())
.radius(LocationFinder.getActualLocation().getAccuracy())
.fillColor(Color.argb(10, 0, 50, 240))
.strokeColor(Color.argb(50, 0, 50, 240))
.strokeWidth(2)
.zIndex(1));
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Jake Wharton的ViewpagerIndicator库.我将选项卡代码与ActionBarSherlock库结合使用.一切正常,但我试图设置选项卡的背景,无法弄清楚如何.我想要一个带有深色标签和浅色片段(标签内容)的黑暗动作栏.
我使用的基本主题是Theme.Sherlock.Light.DarkActionBar.我通过使其成为设置选项卡属性的样式的父级(如文本颜色,指示器颜色等)来扩展此样式.这会导致暗动作条,光标和光碎片.
我找不到任何会改变标签背景的东西.我可以改变它的唯一方法是将整个应用程序更改为黑暗(使用Theme.Sherlock).到目前为止,这是我的代码:
<style name="vpiTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
</style>
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:textColor">#FF000000</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:paddingLeft">16dip</item>
<item name="android:paddingRight">16dip</item>
<item name="android:maxLines">2</item>
</style>
Run Code Online (Sandbox Code Playgroud) 简短版本: 使用android禁用硬件加速:xml中的hardwareAccelerated ="false"会将Theme.Sherlock.Light.DarkActionBar主题的背景颜色更改为更白的"白色". 编辑:这曾经是主要问题.我更改了标题以强调第二个问题.
仅为mapView禁用硬件加速会导致不断重绘.
长版:
API级别14及更高版本默认启用AFAIK硬件加速.(参考)
由于我正在构建和测试API级别16,因此我的硬件加速通常是开启的,这就是我以前所看到的.主题是浅色但不是很纯白色,它是浅灰色(默认).
我在地图上绘制了一些圆形叠加,当我放大时,mapview变得非常迟钝,我在logcat中得到一个"太大而无法渲染到纹理中"的形状.我发现关闭硬件加速可以解决问题.
当我为Android清单中的应用程序(或单个活动)关闭硬件加速时,布局的背景颜色会发生变化.它从浅灰色到非常浅灰色,几乎是纯白色.这是正常的行为吗?
我试着为mapview关闭硬件加速:
if(android.os.Build.VERSION.SDK_INT>=11) {
mapView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); }
Run Code Online (Sandbox Code Playgroud)
这很好地摆脱了纹理太大的错误,因为mapview不是硬件加速的,它还可以加速我的应用硬件的其余部分.这将是理想的解决方案.但是,这会导致另一个问题.它使我使用此代码的覆盖的onDraw方法不断被调用.也就是说,onDraw本身被一遍又一遍地调用,而不需要在mapview上调用invalidate().知道为什么会这样吗?
更新:
下面是一些简单的代码,当仅为mapView(我想要的)禁用硬件加速时,将使用常量重绘重新创建问题:
MapActivity:
public class SettingsActivity extends MapActivity {
private MapView mapView;
private static List<Overlay> overlayList;
private static AccuracyCircleOverlay accuracyCircleOverlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_maps);
mapView = (MapView) findViewById(R.id.map);
overlayList = mapView.getOverlays();
accuracyCircleOverlay = new AccuracyCircleOverlay(this);
overlayList.add(accuracyCircleOverlay);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
覆盖:
public class AccuracyCircleOverlay extends Overlay {
private Context context; …Run Code Online (Sandbox Code Playgroud) 我遇到的问题是,在应用程序被强制停止然后再次手动打开后,我的辅助功能服务无法重新启动,这确实会重新启动其他常规服务。在手动重新启用(预期)、禁用并再次重新启用之前,辅助服务不会启动并再次工作。 不幸的是,应用程序被杀死现在非常常见,非原生 Android 中内置了任务杀手。
概括:
强制停止应用程序会禁用辅助功能服务。这是预料之中的。当接下来使用以下代码手动打开应用程序时,我可以检测到辅助功能服务不再启用:
public static boolean isAccessibilityServiceEnabled(Context context) {
String prefString = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
return prefString != null && prefString.contains(context.getPackageName());
}
Run Code Online (Sandbox Code Playgroud)
我将用户发送到设置以重新启用辅助功能服务。用户重新启用无障碍服务,但无障碍服务不再启动!onCreate 不运行,onServiceConnected 不运行,未接收到辅助功能事件,以下代码将返回 false:
public static boolean isServiceRunning(Context context, Class targetService) {
List<ActivityManager.RunningServiceInfo> serviceInfos = getRunningServices(context);
String targetServiceName = targetService.getName();
for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfos) {
if(serviceInfo.service.getClassName().equals(targetServiceName)) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的代码手动启动该服务。这实际上会触发 onCreate 和 onStartCommand,但不会触发 onServiceConnected,并且不会收到任何辅助功能事件。
context.startService(new Intent(context, MyAccessibilityService.class));
Run Code Online (Sandbox Code Playgroud)
我尝试在上面手动启动该服务后禁用该服务,以便用户被迫再次重新启用它(这将修复它),但这不起作用:
disableSelf();
Run Code Online (Sandbox Code Playgroud)
综上所述,用户认为自己重新启用了该服务,但并不起作用。重新启动设备或禁用该服务并再次重新启用它确实可以修复该问题。
有人知道如何解决这个问题吗?当应用程序被强制停止时,服务被禁用已经够糟糕的了,更糟糕的是,即使用户手动重新启用它也不会启动。
这是在 Android 11 上测试的。
类似问题: 如何检查辅助服务是否崩溃(Android …
有没有办法访问 Android 的广播,即 WiFi 连接当前是一个强制门户(需要网络登录)?Android 似乎内置了这个。如果不是广播接收器,有没有办法检查强制门户检查的结果?我相信它正在使用这个类,它对 API 是隐藏的:
在 4.2 之前,它可能使用:
背景:
我一直在使用我自己的方法来检测 WiFi 是否可能需要登录。我会等待 WiFi 连接状态,然后 ping 一个站点并确保有响应。在大多数情况下,这似乎很有效。另一种策略是执行 HttpRequest 并检查重定向或您收到的响应正文,类似于上面列出的类中的 Android 策略。
但是,Lollipop 的新功能是在 WiFi 没有连接时使用移动数据连接。这意味着我的 ping 方法仍将返回结果,并且不会发生重定向,因为请求将通过移动数据路由。
有没有办法获得 Android 的 WiFi 强制门户的当前状态?如果没有,我们能否确保请求通过 WiFi 传输,即使 Android 没有看到连接?
我正在尝试创建一些非常简单的东西:一个CardView延伸到屏幕高度并且TextView内部应该伸展到卡片宽度的东西.我做了卡填满屏幕垂直android:height="match_parent"的CardView.不过,现在的CardView内容,是一个简单的TextView不能在整个卡设置水平时伸展android:height="match_parent"的TextView.它只是看起来像wrap_content.
请注意,这CardView是放在RecyclerView一个水平LinearLayoutManager.
请注意,android:layout_width="match_parent"使用水平时卡上的设置实际上并不会将其拉伸到屏幕宽度LinearLayoutManager,如果使用垂直方向则相反LinearLayoutManager!我认为这与我的问题有关.
这是CardView xml:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
card_view:contentPadding="8dp"
card_view:cardElevation="8dp"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView_video_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/textView_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="2sp"
android:background="#80000000"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/textView_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#80000000"
style="?android:attr/buttonBarButtonStyle"
android:text="Preview"/>
<Button …Run Code Online (Sandbox Code Playgroud) 我是低功耗蓝牙 (LE) API 的新手。有没有办法检查 Android 设备当前是否连接到任何蓝牙 LE 设备并可能获得这些设备的列表?
BT-LE 设备甚至真的“连接”了吗?我注意到当我的智能手表与我的 Nexus 5 配对/连接时,状态栏(在 KitKat 上)中的蓝牙图标不会变成白色/粗体,就像连接到经典蓝牙设备时那样。
我在经典设备上使用下面的代码。看起来我可以用同样的方式检查 GATT 和 GATT_SERVER,但它们总是断开连接。
更新:所以现在我已经将 Android Lollipop 闪存到我的 Nexus 5,我认为它一定是可能的,因为它用于 SmartLock,并且它以某种方式检测到我的 BT-LE Android 手表已连接。
private BluetoothAdapter getBTAdapter() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
return BluetoothAdapter.getDefaultAdapter();
else {
BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
return bm.getAdapter();
}
}
public boolean isBluetoothConnected() {
if(mBluetoothAdapter == null ||
(mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothProfile.STATE_DISCONNECTED
&& mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP) == BluetoothProfile.STATE_DISCONNECTED
&& mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEALTH) == BluetoothProfile.STATE_DISCONNECTED)
) {
Utils.logDebug(TAG, "GATT_SERVER " + mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.GATT_SERVER));
Utils.logDebug(TAG, "GATT " + …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 AccessibilityService 导航到浏览器中的 URL。我能够找到 URL 栏并在 EditText 中输入 URL,但我找不到按 Enter 键实际转到那里的方法。除了弹出的建议之外,屏幕上也没有任何用于“执行”或“输入”的元素,但根据浏览器的不同,这些节点并不总是可单击的。
是否可以从 AccessibilityService 发送键盘“输入”键事件?