Another possible solution, that I'll eventually need to try out, is hinted at by hackbod's one comment:
Further, in this case there is no reason to do this, because you can use this: https://developer.android.com/reference/android/view/View.html#dispatchProvideStructure(android.view.ViewStructure)
The code comment for dispatchProvideStructure()
states: "Dispatch creation of ViewStructure
down the hierarchy." (emphasis mine).
So, create a NoAssistFrameLayout
subclass of FrameLayout
, override dispatchProvideStructure()
to be a no-op, and use that as your root container for your activity layout. This will block the automatic population of the ViewStructure
for anything in the body of the activity.
It will not, however, block anything that could be inferred from stuff outside your main content area, such as your action bar, as that would be outside the NoAssistFrameLayout
's view hierarchy. Probably there's not much in there that would have privacy implications, but it's a limitation of this technique.
OK, I have tried it, and it does seem to work:
/***
Copyright (c) 2015 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
https://commonsware.com/Android
*/
package com.commonsware.android.assist.no;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewStructure;
import android.widget.FrameLayout;
public class NoAssistFrameLayout extends FrameLayout {
public NoAssistFrameLayout(Context context) {
super(context);
}
public NoAssistFrameLayout(Context context,
AttributeSet attrs) {
super(context, attrs);
}
public NoAssistFrameLayout(Context context,
AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NoAssistFrameLayout(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void dispatchProvideStructure(ViewStructure structure) {
// no, thanks
}
}