Setting Up the Bootstrap-Inspired Theme
First, define custom colors and styles that emulate Bootstrap's look and feel.Step 1: Define Colors
Define the primary Bootstrap colors in yourres/values/colors.xml
file:
1 2 3 4 5 6 7 8 9 10 |
<resources> <color name="primary">#007bff</color> <color name="secondary">#6c757d</color> <color name="success">#28a745</color> <color name="danger">#dc3545</color> <color name="warning">#ffc107</color> <color name="info">#17a2b8</color> <color name="light">#f8f9fa</color> <color name="dark">#343a40</color> </resources> |
Step 2: Define Styles
Define custom styles in yourres/values/styles.xml
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<resources> <!-- Base application theme --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here --> <item name="colorPrimary">@color/primary</item> <item name="colorSecondary">@color/secondary</item> <item name="colorSuccess">@color/success</item> <item name="colorDanger">@color/danger</item> <item name="colorWarning">@color/warning</item> <item name="colorInfo">@color/info</item> <item name="colorLight">@color/light</item> <item name="colorDark">@color/dark</item> </style> <!-- Bootstrap button style --> <style name="BootstrapButton" parent="Widget.AppCompat.Button.Colored"> <item name="android:backgroundTint">@color/primary</item> <item name="android:textColor">@color/light</item> </style> <!-- Bootstrap text style --> <style name="BootstrapText"> <item name="android:textColor">@color/dark</item> <item name="android:textSize">16sp</item> </style> </resources> |
Example: Creating a Bootstrap-Inspired UI
Now, let's create a simple UI with buttons and text views that utilize the Bootstrap-inspired styles.Step 3: Define the Layout
Create an XML layout file (activity_main.xml
) with Bootstrap-inspired components:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bootstrap-Inspired UI" style="@style/BootstrapText" android:layout_gravity="center" android:layout_marginBottom="32dp"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Primary Button" style="@style/BootstrapButton" android:layout_marginBottom="16dp"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Secondary Button" style="@style/BootstrapButton" android:backgroundTint="@color/secondary" android:layout_marginBottom="16dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bootstrap-Inspired Text" style="@style/BootstrapText" android:layout_gravity="center" android:layout_marginTop="32dp"/> </LinearLayout> |
Step 4: Apply the Theme
Apply the Bootstrap-inspired theme to yourMainActivity
in the Android manifest (AndroidManifest.xml
):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bootstraptheme"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
Need Debugging? – Try RobotQA and Start Debugging on Real Devices. Download Plugin