Android Question Using requestWindowFeature() in B4A

corwin42

Expert
Licensed User
Longtime User
With the new StdActionBar library available I'm trying to add a progress bar to the ActionBar.

To enable the progress bar a window feature has to be requested. In Java this is done like this:

B4X:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

I added the following code to Activity_Create sub (5 is the value of Window.FEATURE_INDETERMINATE_PROGRESS:

B4X:
    Dim r As Reflector
    r.Target = r.GetActivity
    r.RunMethod4("requestWindowFeature", Array As Object (5), Array As String ("java.lang.int"))

The problem is that window features have to be requested before anything is added to the activity.

I get the following error:

** Activity (main) Create, isFirst = true **
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:249)
at android.app.Activity.requestWindowFeature(Activity.java:3298)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at de.amberhome.NavDrawer.main._activity_create(main.java:293)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at de.amberhome.NavDrawer.main.afterFirstLayout(main.java:98)
at de.amberhome.NavDrawer.main.access$100(main.java:16)
at de.amberhome.NavDrawer.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
android.util.AndroidRuntimeException: requestFeature() must be called before adding content

I even tried to add the code to Globals or Process_Globals Subs but without luck.

Any chance to call this method?
 
Top