标签:des android style blog http io ar color os
1.在QQ一些APP当中有是弹出一个半透明的搜索框的,其实这种效果就是很多种方法,自定义一个Dialog,或者直接将activity的背景变成半透明的也可以的。
下面就是将activity变成半透明的方法。效果图如下:
2.代码如下:
在styles.xml文件中添加自定义Theme
1 <style name="MyTranspaent"> 2 3 <item name="android:windowBackground">@color/transparent_background</item> 4 <item name="android:windowNoTitle">true</item> 5 <item name="android:windowIsTranslucent">true</item> 6 <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> 7 </style>
搜索界面的Activity:
1 public class SecondActivity extends Activity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_second); 7 } 8 9 @Override 10 public boolean onCreateOptionsMenu(Menu menu) { 11 // Inflate the menu; this adds items to the action bar if it is present. 12 getMenuInflater().inflate(R.menu.second, menu); 13 return true; 14 } 15 16 @Override 17 public boolean onTouchEvent(MotionEvent event) { 18 19 switch (event.getAction()) { 20 case MotionEvent.ACTION_DOWN: 21 SecondActivity.this.finish(); 22 break; 23 24 default: 25 break; 26 } 27 28 return super.onTouchEvent(event); 29 } 30 31 }
activity_second.xml文件:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="horizontal" 6 tools:context=".SecondActivity" > 7 8 <EditText 9 android:id="@+id/ed" 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:layout_weight="1.0" 13 android:background="#F8F8FF" 14 android:drawableLeft="@drawable/ic_search_normal" 15 android:hint="请输入要查询内容" 16 android:textColor="#000033" /> 17 18 </LinearLayout>
主界面里面就是一个button来弹出这个activity
1 public class MainActivity extends Activity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 8 findViewById(R.id.Button01).setOnClickListener(new OnClickListener() { 9 10 @Override 11 public void onClick(View v) { 12 Intent i = new Intent(); 13 i.setClass(MainActivity.this, SecondActivity.class); 14 startActivity(i); 15 } 16 }); 17 18 } 19 20 }
关键的就是要在Manifest.xml文件中给弹出的activity添加theme
1 <activity 2 android:name="com.example.compass.SecondActivity" 3 android:label="@string/title_activity_second" 4 android:theme="@style/MyTranspaent" > 5 </activity>
标签:des android style blog http io ar color os
原文地址:http://www.cnblogs.com/liangstudyhome/p/4123522.html