728x90
반응형
안드로이드에서 Floating button 사용하는 방법.
1. gradle 에 dependency 추가
implementation 'com.google.android.material:material:1.12.0'
2. xml 에 floating button 생성
<!-- 플로팅 버튼 -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="16dp" />
확장된 버전인 ExtendedFloatingActionButton 사용법
1. theme에 MaterialComponets에 해당하는 ActionBar 설정 (그냥 AppTheme 의 AppCompat부분을 MaterialComponents로 변경해줌)
<style name="FloatingTheme" parent="Theme.MaterialComponent.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
2. AndroidManifest.xml에서 플로팅버튼 띄워줄 activity에 해당 테마 적용
3. xml파일에서 ExtendedFloatingActionButton 생성
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"
android:text="Menu"
android:paddingLeft="10dp"
android:drawableRight="@drawable/icon_menu_about" />
* ExtendedFloatingActionButton은 글자와 아이콘을 같이 사용 가능함
728x90
반응형
'Android > 개발 정보' 카테고리의 다른 글
안드로이드 빌드 하는 장치 정보 가져오기 (0) | 2024.07.10 |
---|---|
Android floating button 움직이도록 만들기 (0) | 2024.06.24 |
android 버전 14 업데이트로 인한 broadcast 변경 (0) | 2024.05.30 |
Android studio 다른 버전으로 여러 개 사용하기 (1) | 2024.05.16 |
Android 색상 제대로 안나올 때 (0) | 2023.07.03 |