Android 원 각 테두리 대화 상자 구현 방법

머리말
최근 에 원 각 테두리 의 대화 상자 디자인 도 를 실현 하려 면 인터넷 에서 여러 가지 실현 을 찾 아 보 았 는데 차이 가 많 지 않 습 니 다.그 중에서 영감 을 얻 고 다른 방식 을 실 현 했 습 니 다layer-list:
먼저 실현 효 과 를 살 펴 보면 다음 과 같다.

우선 drawable 디 렉 터 리 에 원 각 배경 파일 dialog 를 정의 합 니 다.corner_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
 <shape android:shape="rectangle">
 <solid android:color="@color/dark_green" /> 
 <corners android:radius="6dp" /> <!--   --> 
 </shape> 
</item> 
<item android:top="8dp" android:right="8dp" android:left="8dp" android:bottom="8dp"> <!--     --> 
 <shape android:shape="rectangle"> 
 <solid android:color="@color/white"/> 
 <corners android:radius="6dp" /> 
 <padding android:bottom="8dp" android:left="8dp" android:right="8dp" android:top="8dp"/> 
 </shape>
</item>
</layer-list>
styles.xml 파일 에서 대화 상자 테마 스타일 을 정의 합 니 다.

<style name="myCorDialog" parent="android:style/Theme.Dialog"> 
 <item name="android:windowBackground">@drawable/dialog_corner_bg</item> <!--      --> 
 <item name="android:windowNoTitle">true</item> <!--      --> 
 <item name="android:backgroundDimEnabled">true</item> <!--      --> 
</style>
실례 화 대화 상자 builder 에서 스타일 을 지정 하면 됩 니 다

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.myCorDialog);
총결산
이상 은 이 글 의 전체 내용 입 니 다.본 논문 의 내용 이 여러분 의 학습 이나 업무 에 어느 정도 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 면 댓 글 을 남 겨 주 십시오.

좋은 웹페이지 즐겨찾기