Android Question How to get the actionbar title as a label

thedesolatesoul

Expert
Licensed User
Longtime User
I want to set the Actionbar title text size. I can do it by defining styles but I am not sure how I can get the whole label and do whatever I want with it.

This is what I am trying to do:
B4X:
' To implement
'Int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
'TextView title = (TextView) findViewById(titleId);
'title.setTextSize(20);
Sub GetTitleLabel As Label
    Dim JO As JavaObject
    jo = GetContext
    JO = JO.RunMethod("getResources",Null)
    JO = JO.RunMethod("getSystem",Null)
    Dim ID As Int
    ID = jo.RunMethod("getIdentifier", Array As Object("action_bar_title","id","android"))
   
    Log(ID)
    JO = Activity
    Log(JO)
    JO = JO.RunMethod("findViewById", Array As Object(ID))

    Log(JO)
End Sub

Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub

Unfortunately the last JO logs and uninitialized object.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code works:
B4X:
Sub GetTitleLabel As Label
   Dim jo As JavaObject = Activity
   jo = jo.RunMethod("getContext", Null)
  Dim v As JavaObject = jo.RunMethodJO("getWindow", Null).RunMethodJO("getDecorView", Null)
  Dim resId As Int = GetContext.RunMethodJO("getResources",Null).RunMethod("getIdentifier", Array As Object("action_bar_title","id","android"))
   Return v.RunMethod("findViewById", Array(resId))
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
either .. In the Designer > Activity properties > Title

or in code
B4X:
Activity.Title = "My Title"
 
Upvote 0
Top