The Android settings window is dimmed, the rounded corner button and the use of include and merge, androidmerge

Source: Internet
Author: User

The Android settings window is dimmed, the rounded corner button and the use of include and merge, androidmerge

I wrote a small Demo yesterday and implemented several small functions. I posted it today. These Feature items are put together because they are relatively simple. Let's take a look at it first:



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 {p Rivate 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 o NClickListenerImp (); layoutParams = getWindow (). getAttributes ();} class onClickListenerImp implements OnClickListener {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubif (v = btnSet) {// darken the window to layoutParams. dimAmount = 0.7f; // 0.0 ~ 1.0layoutParams.alpha = 0.6f; // 0.0 black ~ 1.0 original window getWindow (). setAttributes (layoutParams); Toast. makeText (Main. this, "Set Dark", Toast. LENGTH_SHORT ). show ();} else if (v = btnCancel) {// deselect the window to darken 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 present. 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 AndroidManifest.xml.int id = item. getItemId (); if (id = R. id. action_settings) {return true;} return super. onOptionsItemSelected (item );}}

A bunch of la s are shown below:

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:background="#40ff50"    android:orientation="vertical"    tools:context="com.example.includelayoutdemo.Main" >    <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="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_margin="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_height="wrap_content"        android:layout_gravity="center"        android:orientation="horizontal" >        <Button            android:id="@+id/btnSet"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginRight="10dp"            android:background="@drawable/zj_round_btn"            android:padding="5dp"            android:text="Set Dark"            android:textColor="#80ffffff" />        <Button            android:id="@+id/btnCancel"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="@drawable/zj_round_btn_more"            android:padding="5dp"            android:text="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:id="@+id/inc_other"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        layout="@layout/another" />    <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" /></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 are also shape files and rounded rectangular backgrounds:

<?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>


Reprinted please indicate the source: Zhou mu Shui CSDN blog http://blog.csdn.net/zhoumushui

My GitHub: Zhou mu Shui's GitHub https://github.com/zhoumushui







Related Article

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.