My Android Advanced tour------> How do I turn activity into a translucent dialog box?

Source: Internet
Author: User



My Android Advanced tour------> How do I turn activity into a translucent dialog box? There are two aspects to consider: dialog box and translucent.

You can set activity as a dialog style by specifying the Theme.dialog theme when you define the activity.

You can change the background image of an activity by modifying the Android:windowbackground property value of the Theme.dialog theme. If the background image uses a translucent image, the activity becomes a translucent dialog box. In order to modify the Android:windowbackground property, you can define a new theme that inherits from the Theme.dialog code as follows:

Create two XML files under Res/values, one for theme style resources Dialog_styles.xml,

One for the color resource dialog_colors.xml.


Dialog_styles.xml, themed style named Dialog_translucent

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <style name= "dialog_translucent" parent= "@ Android:style/theme.dialog ">        <item name=" Android:windowbackground "> @color/translucent_background </item>        <item name= "android:windowistranslucent" >true</item>        <item name= "Android: Windownotitle ">true</item>        <item name=" Android:windowanimationstyle "> @android: style/ Animation.translucent</item<span style= "White-space:pre" ></span>>    </style></ Resources>
Dialog_colors.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources> <color    name = "Translucent_background" ># 00000000</color></resources>

Specify a custom theme for the activity in Androidmanifest.xml,Android:theme= "@style/dialog_translucent"

The code is as follows:

       <activity            android:name= ". Dialogactivity "            android:configchanges=" orientation|keyboardhidden|screensize "            android:label=" @string/ App_name "            android:theme=" @style/dialog_translucent "><!--reference a custom theme-->>            <intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android:name= " Android.intent.category.LAUNCHER "/>            </intent-filter>        </activity>



==================================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

==================================================================================================

  

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My Android Advanced tour------> How do I turn activity into a translucent dialog box?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.