Overriding Activities and Fragments
Overriding Activities and Fragments
You can customize the UI by subclassing UI elements and then injecting them into the framework.
You should always do this just after Chat SDK activation.
Check out the example here.
Override Activity
For example, to override the chat activity you would subclass the PostRegistrationActivity
then use:
There is a method available for each of the activities in the app.
When you override the activity you can then override any of the functions in that activity. You can easily override the layout file like this:
Note: Don't forget to register the activity in your AndroidManifest.xml
Override Fragment
Using the Fragments in your app
Usually, the fragments are embedded in the MainActivity
. The main activity reloads the fragments when the activity resumes. If you want to use the fragments in your own activity, you should either inherit from MainActivity
or make sure that you call loadData()
in your activity onResume()
.
Override the ProfileFragment
The profile fragment is hosted within the profile activity. It is defined withinactivity_profile.xml
. To override this fragment, you will need to subclass it and update the layout file:
Replace the standard profile fragment with your custom profile fragment.
Override the ChatActivity
If you are overriding the ChatActivity
you will also need to define the main activity for your app like this:
When the user clicks back from the ChatActivity
they will be taken to the app's main activity.
Override ChatView
To do this first you need to override the ChatActivity
. Create a new subclass of the ChatActivity
Also, make a new xml layout file and copy the contents of activity_chat
into it. Make sure you give this layout file a new name like custom_activity_layout
As you can see above, we override the getLayout()
method and provide our custom layout file.
After Chat SDK initialization, register this subclass:
Make a new subclass of the ChatView
called CustomChatView
.
Open your custom_activity_layout
file and find the section:
Change this to:
Now the CustomChatView
will be inflated into the ChatActivity
and you can customize it as necessary.
Last updated