Android Settings window dimmed, fillet buttons and use of include and merge

Source: Internet
Author: User

Yesterday wrote a small demo, implemented a few small features, posted today. Because these several feature are relatively simple, so put together. First Look at:



On the code:

Main:

Package Com.example.includelayoutdemo;import Android.app.activity;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.view.view.onclicklistener;import Android.view.window;import Android.view.windowmanager;import Android.widget.button;import Android.widget.toast;public class Main extends Activity {private Button btnset;private Button btncancel;private windowmanager.layoutparams layoutparams; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); btnSet = (Button) Findviewbyid (r.id.btnset); btncancel = (Button) Findviewbyid (r.id.btncancel); Btnset.setonclicklistener (new Onclicklistenerimp ()); Btncancel.setonclicklistener (new Onclicklistenerimp ()); layoutparams = GetWindow (). GetAttributes ();} Class Onclicklistenerimp implements Onclicklistener {@Overridepublic void OnClick (View v) {//TODO auto-generated method s tubif (v = = Btnset) {//dims the window Layoutparams.dimamount = 0.7f;//0.0~1.0layoutparams.alpha = 0.6f;//0.0 All Black ~1.0 the original Window GetWindow (). SetAttributes (Layoutparams); Toast.maketext (Main.this, "Set Dark", Toast.length_short). Show (); else if (v = = btncancel) {//cancel window dims layoutparams.dimamount = 1.0f;layoutparams.alpha = 1.0f;getwindow (). SetAttributes ( Layoutparams); Toast.maketext (Main.this, "Cancel Dark", Toast.length_short). Show ();}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar will//automatically handle clicks on the Home/up button so long//as you specify a parent activity in and RoidManifest.xml.int id = item.getitemid (); if (id = = r.id.action_settings) {return true;} return super.onoptionsitemselected (item);}}

Here's a bunch of layouts:

Main.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:backg Round= "#40ff50" android:orientation= "vertical" tools:context= "Com.example.includelayoutdemo.Main" > <textvi EW android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_margin= "5DP        "Android:background=" @drawable/zj_round_btn_more "android:gravity=" center "android:text=" Main "        Android:textcolor= "#80ffffff" android:textsize= "80DP"/> <include android:id= "@+id/inc_other"    Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" layout= "@layout/other"/> <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_m Argin= "5DP" android:background= "@drawablE/zj_round_btn_more "android:gravity=" center "android:text=" Main "android:textcolor=" #80ffffff " Android:textsize= "80DP"/> <linearlayout android:layout_width= "Wrap_content" Android:layout_heigh            t= "wrap_content" android:layout_gravity= "center" android:orientation= "Horizontal" > <button Android:id= "@+id/btnset" android:layout_width= "wrap_content" android:layout_height= "Wrap_con Tent "android:layout_marginright=" 10DP "android:background=" @drawable/zj_round_btn "Andro            id:padding= "5DP" android:text= "Set Dark" android:textcolor= "#80ffffff"/> <button Android:id= "@+id/btncancel" android:layout_width= "wrap_content" android:layout_height= "Wrap_co Ntent "android:background=" @drawable/zj_round_btn_more "android:padding=" 5DP "Android:tex         t= "Cancel Dark"   Android:textcolor= "#80ffffff"/> </LinearLayout></LinearLayout> 

Other.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android: Layout_margin= "5DP" android:background= "@drawable/zj_round_btn_more" android:gravity= "Center" Android : text= "Include-other" android:textcolor= "#80ffffff" android:textsize= "80DP"/> <include Android Oid:id= "@+id/inc_other" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" layou t= "@layout/another"/> <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_con Tent "android:layout_margin=" 5DP "android:background=" @drawable/zj_round_btn_more "android:gravity=" C Enter "android:text=" Include-other "android:textcolor=" #80ffffff "android:textsize=" 80DP "/></linearlayout> 

Another.xml

<?xml version= "1.0" encoding= "Utf-8"? ><merge xmlns:android= "Http://schemas.android.com/apk/res/android"    android:background= "#ffff00" >    <textview        android:layout_width= "Fill_parent"        android: layout_height= "Wrap_content"        android:layout_margin= "5DP"        android:background= "@drawable/zj_round_btn_ More "        android:gravity=" center "        android:text=" Merge-another "        android:textcolor=" #80ffffff "        Android:textsize= "80DP"/></merge>

There is also a shape file, rounded rectangle background:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"    android:shape= "Rectangle" >    <solid android:color= "#30ffffff"/>    <corners android:radius= " 7DP "/></shape>


Reprint Please specify source: Zhou Mushi's csdn blog Http://blog.csdn.net/zhoumushui

My github: Zhou Mushi's GitHub Https://github.com/zhoumushui




Android Settings window dimmed, fillet buttons and use of include and merge

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.