When I add the following code to the layout.xml file, the app crashes, when the layout is loaded.
Code:
<android.support.design.button.MaterialButton
android:id="@+id/b_p_add"
android:layout_width="143dp"
android:layout_height="38dp"
android:layout_below="@+id/et_p_addl_notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp" />
I checked my app gradle file and found
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
So, the required design, support, appcompat dependencies are present.
Note: No other code apart from the above has been added, ie, the app works fine if I don't add the Material button in XML and crashes, if I add the Material Button in the XML.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
for MaterialButton to work, your app theme must inherit from Theme.MaterialComponents (or a descendant) Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.