Android Pop-up Activity setting size method _android

Source: Internet
Author: User

How to set the size of the activity so that your window does not look full-screen. Some netizens may know how to do this through themes such as theme.dialog, but tell everyone to set the principle that the activity will not be displayed in full screen. The Android theme is also largely done by defining style, and the principle of implementation is that you can look directly at the definition in the Android framework and give a simpler, but relatively flexible, approach today For example, do not theme.dialog in the border, below together to see the implementation of the custom activity size.

1. Create a style file to your project, save in Res/values/styles.xml, where the filename can not be arbitrarily modified, the content is, note that the use of UTF-8 encoding when saving.

Java code

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<style name= "theme.android123" parent= "Android:style/theme.dialog" >
<item name= "Android:windowbackground" > @drawable/bg</item>
</style>
</resources>

2. Above we define the theme style for theme.android123, the parent style is still implemented from the Theme.dialog, but we customize the background, location in DRAWABLE/BG, where we create a bg.xml file into res/ In the Drawable folder, the contents of the Bg.xml are

Java code

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<padding android:left= "15DP" android:top= "15DP" android:right= "15DP" android:bottom= "15DP"/>
<stroke android:width= "3dip" color= "#000000"/>
<corners android:radius= "5DP"/>
<solid android:color= "#ffffff"/>
</shape>


Inside we define a Shape object that implements the background drawable shape, where the padding represents the distance border, where we set the spacing of the left, top, right, and bottom four positions. Stroke can produce some 3D stereo effect, corners is Four Corners, Radisu properties can set the radius, the greater the value of the more smooth, according to the operation of the effect you can fine-tune, the last soild is filled with color, here we use the FFFFFF to express pure white.

3. Finally in Androidmanifest.xml, add a android:theme attribute to your Activity node, and the value is @style/theme.android123

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.