Floating Action Button in an Accessibility Service (Wont Appear)












-1















I have followed a tutorial to create a floating action button using an API (https://github.com/yavski/fab-speed-dial) and if I do this on a normal activity class the menu works fine and works as expected.



I am trying to merge it with an accessibility service (That works as an overlay): https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/index.html?index=..%2F..index#0



The issue is when I try to add it in an AccessibilityService I am not getting the floating action button appearing when i enable the setting. So I am assuming it is to do with the layout not applying when the service is started



public class GlobalActionBarService extends AccessibilityService {

FrameLayout mLayout;

@Override
protected void onServiceConnected() {
// Create an overlay and display the action bar
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);

FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu);
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {

@Override
public boolean onPrepareMenu(NavigationMenu navigationMenu) {
return true;
}

@Override
public boolean onMenuItemSelected(MenuItem menuItem) {
Toast.makeText(GlobalActionBarService.this, menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}

@Override
public void onMenuClosed() {

}

});


Layout:



<?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:padding="16dp">

<io.github.yavski.fabspeeddial.FabSpeedDial
android:id="@+id/accessibleMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabGravity="bottom_end"
app:fabMenu="@menu/main_menu"
app:miniFabBackgroundTint="@android:color/white"
app:miniFabDrawableTint="@color/colorPrimaryDark"
app:miniFabTitleTextColor="@color/colorPrimaryDark" />



</FrameLayout>


styles.xml



<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>









share|improve this question

























  • One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

    – TheWanderer
    Jan 19 at 14:24











  • @TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

    – godlypython
    Jan 19 at 14:37











  • It looks fine to me. Are you sure the service is actually starting?

    – TheWanderer
    Jan 19 at 15:27











  • It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

    – godlypython
    Jan 19 at 15:49











  • You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

    – TheWanderer
    Jan 19 at 16:02
















-1















I have followed a tutorial to create a floating action button using an API (https://github.com/yavski/fab-speed-dial) and if I do this on a normal activity class the menu works fine and works as expected.



I am trying to merge it with an accessibility service (That works as an overlay): https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/index.html?index=..%2F..index#0



The issue is when I try to add it in an AccessibilityService I am not getting the floating action button appearing when i enable the setting. So I am assuming it is to do with the layout not applying when the service is started



public class GlobalActionBarService extends AccessibilityService {

FrameLayout mLayout;

@Override
protected void onServiceConnected() {
// Create an overlay and display the action bar
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);

FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu);
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {

@Override
public boolean onPrepareMenu(NavigationMenu navigationMenu) {
return true;
}

@Override
public boolean onMenuItemSelected(MenuItem menuItem) {
Toast.makeText(GlobalActionBarService.this, menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}

@Override
public void onMenuClosed() {

}

});


Layout:



<?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:padding="16dp">

<io.github.yavski.fabspeeddial.FabSpeedDial
android:id="@+id/accessibleMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabGravity="bottom_end"
app:fabMenu="@menu/main_menu"
app:miniFabBackgroundTint="@android:color/white"
app:miniFabDrawableTint="@color/colorPrimaryDark"
app:miniFabTitleTextColor="@color/colorPrimaryDark" />



</FrameLayout>


styles.xml



<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>









share|improve this question

























  • One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

    – TheWanderer
    Jan 19 at 14:24











  • @TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

    – godlypython
    Jan 19 at 14:37











  • It looks fine to me. Are you sure the service is actually starting?

    – TheWanderer
    Jan 19 at 15:27











  • It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

    – godlypython
    Jan 19 at 15:49











  • You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

    – TheWanderer
    Jan 19 at 16:02














-1












-1








-1








I have followed a tutorial to create a floating action button using an API (https://github.com/yavski/fab-speed-dial) and if I do this on a normal activity class the menu works fine and works as expected.



I am trying to merge it with an accessibility service (That works as an overlay): https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/index.html?index=..%2F..index#0



The issue is when I try to add it in an AccessibilityService I am not getting the floating action button appearing when i enable the setting. So I am assuming it is to do with the layout not applying when the service is started



public class GlobalActionBarService extends AccessibilityService {

FrameLayout mLayout;

@Override
protected void onServiceConnected() {
// Create an overlay and display the action bar
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);

FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu);
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {

@Override
public boolean onPrepareMenu(NavigationMenu navigationMenu) {
return true;
}

@Override
public boolean onMenuItemSelected(MenuItem menuItem) {
Toast.makeText(GlobalActionBarService.this, menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}

@Override
public void onMenuClosed() {

}

});


Layout:



<?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:padding="16dp">

<io.github.yavski.fabspeeddial.FabSpeedDial
android:id="@+id/accessibleMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabGravity="bottom_end"
app:fabMenu="@menu/main_menu"
app:miniFabBackgroundTint="@android:color/white"
app:miniFabDrawableTint="@color/colorPrimaryDark"
app:miniFabTitleTextColor="@color/colorPrimaryDark" />



</FrameLayout>


styles.xml



<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>









share|improve this question
















I have followed a tutorial to create a floating action button using an API (https://github.com/yavski/fab-speed-dial) and if I do this on a normal activity class the menu works fine and works as expected.



I am trying to merge it with an accessibility service (That works as an overlay): https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/index.html?index=..%2F..index#0



The issue is when I try to add it in an AccessibilityService I am not getting the floating action button appearing when i enable the setting. So I am assuming it is to do with the layout not applying when the service is started



public class GlobalActionBarService extends AccessibilityService {

FrameLayout mLayout;

@Override
protected void onServiceConnected() {
// Create an overlay and display the action bar
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);

FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu);
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {

@Override
public boolean onPrepareMenu(NavigationMenu navigationMenu) {
return true;
}

@Override
public boolean onMenuItemSelected(MenuItem menuItem) {
Toast.makeText(GlobalActionBarService.this, menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}

@Override
public void onMenuClosed() {

}

});


Layout:



<?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:padding="16dp">

<io.github.yavski.fabspeeddial.FabSpeedDial
android:id="@+id/accessibleMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabGravity="bottom_end"
app:fabMenu="@menu/main_menu"
app:miniFabBackgroundTint="@android:color/white"
app:miniFabDrawableTint="@color/colorPrimaryDark"
app:miniFabTitleTextColor="@color/colorPrimaryDark" />



</FrameLayout>


styles.xml



<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>






java android menu floating-action-button






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 14:59







godlypython

















asked Jan 19 at 14:14









godlypythongodlypython

467




467













  • One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

    – TheWanderer
    Jan 19 at 14:24











  • @TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

    – godlypython
    Jan 19 at 14:37











  • It looks fine to me. Are you sure the service is actually starting?

    – TheWanderer
    Jan 19 at 15:27











  • It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

    – godlypython
    Jan 19 at 15:49











  • You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

    – TheWanderer
    Jan 19 at 16:02



















  • One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

    – TheWanderer
    Jan 19 at 14:24











  • @TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

    – godlypython
    Jan 19 at 14:37











  • It looks fine to me. Are you sure the service is actually starting?

    – TheWanderer
    Jan 19 at 15:27











  • It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

    – godlypython
    Jan 19 at 15:49











  • You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

    – TheWanderer
    Jan 19 at 16:02

















One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

– TheWanderer
Jan 19 at 14:24





One thing I see is that you're using a redundant root element. Instead of new FrameLayout(this), and then inflating your XML into that, you should be using (FrameLayout) LayoutInflater.from(this).inflate(R.layout.action_bar, null) directly. You also should try assigning a definite height and width to the FAB itself. It's possible that wrap_content is 0.

– TheWanderer
Jan 19 at 14:24













@TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

– godlypython
Jan 19 at 14:37





@TheWanderer Hmm I tried these changes but still no result. Is there anything else you can see that is causing nothing to appear? Is it to do with perhaps the ` FabSpeedDial fabSpeedDial = (FabSpeedDial) mLayout.findViewById(R.id.accessibleMenu)` ?

– godlypython
Jan 19 at 14:37













It looks fine to me. Are you sure the service is actually starting?

– TheWanderer
Jan 19 at 15:27





It looks fine to me. Are you sure the service is actually starting?

– TheWanderer
Jan 19 at 15:27













It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

– godlypython
Jan 19 at 15:49





It was working before..Now it isn't? I'll trace my steps back to where it was working and try again step by step and will update you soon.

– godlypython
Jan 19 at 15:49













You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

– TheWanderer
Jan 19 at 16:02





You can insert a log inside onServiceConnected() and then try to find that in the logcat, or you could insert a breakpoint and install the app with Shift+F9. If you're using an LG phone, reinstalling the app a lot quickly will break the Accessibility Service. Try a reboot.

– TheWanderer
Jan 19 at 16:02












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267975%2ffloating-action-button-in-an-accessibility-service-wont-appear%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267975%2ffloating-action-button-in-an-accessibility-service-wont-appear%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage