# 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. Checkout the example [here](https://github.com/chat-sdk/chat-sdk-android/blob/master/app-demo/src/main/java/sdk/chat/demo/examples/override/OverrideViewExample.java). ### Override Activity For example, to override the chat activity you would subclass the `PostRegistrationActivity` then use: ```Java ChatSDKUI.setPostRegistrationActivity(CustomPostRegistrationActivity.class); ``` 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: ``` @Override protected int getLayout() { return R.layout.activity_custom_post_registration; } ``` ### Override Fragment ```Java ChatSDKUI.setPrivateThreadsFragment(new CustomPrivateThreadsFragment()); ``` ### Override the ChatActivity If you are overriding the `ChatActivity` you will also need to define the main activity for your app like this: ``` ChatSDK.ui().setMainActivity(YourMainActivity.class); ``` 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` ``` public class CustomChatActivity extends ChatActivity { protected @LayoutRes int getLayout() { return R.layout.custom_activity_chat; } } ``` 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: ``` ChatSDK.ui().setChatActivity(CustomChatActivity.class); ``` Make a new subclass of the `ChatView` called `CustomChatView`. ``` public class CustomChatView extends ChatView { public CustomChatView(Context context) { super(context); } } ``` Open your `custom_activity_layout` file and find the section: ``` <sdk.chat.ui.views.ChatView android:id="@+id/chatView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/messageInputLinearLayout" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> ``` Change this to: ``` <sdk.chat.ui.views.CustomChatView android:id="@+id/chatView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/messageInputLinearLayout" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> ``` Now the `CustomChatView` will be inflated into the `ChatActivity` and you can customize it as necessary.