標籤:android style blog http color 使用 os io
原文:http://blog.csdn.net/sodino/article/details/58221471.Activity全透明
同學zzm給了這個有趣的代碼,現在公布出來。
先在res/values下建colors.xml檔案,寫入:
- <? xml version = "1.0" encoding = "UTF-8" ?>
- < resources >
- < color name = "transparent" > #9000 </ color >
- </ resources >
這個值設定了整個介面的透明度,為了看得見效果,現在設為透明度為56%(9/16)左右。
再在res/values/下建styles.xml,設定程式的風格
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="Transparent">
- <item name="android:windowBackground">@color/transparent</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
- </style>
- </resources>
最後一步,把這個styles.xml用在相應的Activity上。即在AndroidManifest.xml中的任 意<activity>標籤中添加
- android:theme = "@style/transparent"
如果想設定所有的activity都使用這個風格,可以把這句標籤語句添加在<application>中。
最後運行程式,哈哈,是不是發現整個介面都被蒙上一層半透明了。最後可以把背景色#9000換成#0000,運行程式後,就全透明了,看得見背景下 的所有東西可以卻都操作無效。呵呵....
2.Dialog全透明
1.準備保留邊框的全透明素材如:
2.在values中建立一styles.xml檔案,內容如下:
- <?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="TANCStyle" parent="@android:style/Theme.Dialog">
<!-- 更換背景圖片實現全透明 -->
<item name="android:windowBackground">@drawable/panel_background_sodino1</item>
<!-- 螢幕背景不變暗 -->
<item name="android:backgroundDimEnabled">false</item>
<!-- 更改對話方塊標題列 -->
<item name="android:windowTitleStyle">@style/TitleStyle</item>
</style>
<style name="TitleStyle" parent="@android:style/DialogWindowTitle">
<item name="android:textAppearance">@style/TitleText</item>
</style>
<style name="TitleText" parent="@android:style/TextAppearance.DialogWindowTitle">
<!-- 設定Dialog標題列文字顏色。 -->
<item name="android:textColor">#000</item>
</style>
</resources>
3.在layout檔案夾下建立一檔案句為main_dialog.xml,內容如下:
[xhtml] view plaincopy
- <?xml version="1.0" encoding="UTF-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#0000">
- <ScrollView android:id="@+id/ScrollView01"
- android:layout_width="wrap_content"
- android:layout_height="200px"
- android:layout_below="@+id/ImageView01"
- android:background="#0000">
- <TextView android:id="@+id/TextView01"
- android:text="SodinoText"
- android:textColor="#f000"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#0000"
- ></TextView>
- </ScrollView>
- <Button android:id="@+id/btnCancel"
- android:layout_below="@id/ScrollView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:text="Cancel">
- </Button>
- </RelativeLayout>
4.Activity代碼如下:
[xhtml] view plaincopy
- package lab.sodino.tanc;
- import android.app.Activity;
- import android.app.Dialog;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class TANCAct extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button btnShow = (Button) findViewById(R.id.btnShow);
- btnShow.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View view) {
- showTANC(
- "This is my custom dialog box",
- "TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int) from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",
- "http://blog.csdn.net/sodino");
- }
- });
- }
- private void showTANC(String header, String content, String url) {
- final Dialog dialog = new Dialog(this, R.style.TANCStyle);
- dialog.setContentView(R.layout.main_dialog);
- dialog.setTitle(header);
- dialog.setCancelable(true);
- TextView textView01 = (TextView) dialog.findViewById(R.id.TextView01);
- textView01.setText(content + content + content);
- Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
- btnCancel.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View view) {
- dialog.cancel();
- }
- });
- dialog.show();
- }
- }
最後:
另附 android系統內建表徵圖大全(1.5 1.6 2.1)
http://since2006.com/android/1.5-drawables.php