2012年9月30日

[CSS]讓版面聽話-Reset.css

問題:在開發Web時,常遇到各家瀏覽器不同的預設,導致設計師日以繼夜的爆肝。

最佳的方法「Reset CSS」

世界知名的 CSS 大師「Eric A. Meyer」整理出一個很棒的解決方法「Reset CSS」,針對 CSS 語法最容易出問題的部份~例如 margin 外間距,各大瀏覽器最常發生不一致的狀況,現在將 margin 全部統一歸 0 ,其他部份,文字大小和行高也全部統成一樣的大小 …. 等,只要掛上這一段「Reset CSS」語法,就可以讓所有的各大瀏覽器乖乖聽話,呈現一樣的結果,CSS 的大同世界就在這裡啊!

/* v1.0 | 20080212 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* remember to define focus styles! */
:focus {
    outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
    text-decoration: none;
}
del {
    text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

下載網站:http://meyerweb.com/eric/tools/css/reset/reset.css

參考來源:flycan


2012年9月20日

[Android]Android連不到WebAPI

問題:在開發Android時,連不上Web的API,該怎麼辦?

/*
step 1:先檢查是否有加入權限
*/
//AndroidManifest.xml


//*.java
@Override
    public void onCreate(Bundle savedInstanceState) {
  //加入以下兩行
     StrictMode
.setVmPolicy(new StrictMode
.VmPolicy
.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build());
     StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites()
.detectNetwork().penaltyLog().build());
  
  /*
  StrictMode
  This class is not available with API level 8.
  所以要用在2.3以上喔
  */
     
  super.onCreate(savedInstanceState);


參考網站:Android™ 2.1 android.R.drawable Icon Resources

[Android]Android內建的圖示

問題:在開發Android時,沒有美工的頭腦時,網路上下載圖檔又擔心版權問題,所以直接使用Android 內建的圖示

//*.java
ImageView btnImg_Help = (ImageView)findViewById(R.id.Img_Help); 
btnImg_Help.setImageResource(android.R.drawable.ic_menu_help);

//*.xml
android:icon="@android:drawable/ic_menu_save"

參考網站:Android™ 2.1 android.R.drawable Icon Resources

2012年8月16日

[PHP]集合運算


交集: array_intersection()
差集: array_diff()
聯集: 沒有內建,不過可先透過 array_merge 將兩個陣列集合在一起,再利用 array_unique 去除重複的元素
function array_union($a, $b) {
$union = array_merge($a, $b); // duplicates may still exist
$union = array_unique($union);
return $union;
}

2011年12月14日

[PHP]JSON的使用

1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);  
echo $arr2=json_encode($arr); 
$stdin=get_object_vars(json_decode($arr2));
foreach ($stdin as $k => $v) {
echo "$k = \"$v\"\n"; // print json_decode key => value.
}
?>

2011年12月9日

[Android] 開發小問題

1. indexOf判斷中文字串
//indexOf的句子,不知道為什麼第一個字不會去找,怪災。
replaced=" "+result.get(i);

//年
if(replaced.indexOf("年")>0)
{
score[i]=score[i]+1;
}

2.使用正規表示法判斷數字
//判斷數字
     Pattern p=Pattern.compile("[0-9]{1,2}");
     Matcher m=p.matcher(replaced);
     if(m.find()){
      //正確
     }

//{n,m} 表示前一個字元或者前一個RE出現n到m次
//[0-9] 0-9的集合

2011年12月5日

[Android]Activity返回上一頁

page1

package Demo;
 
/* import相關class */
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
 
public class Page1 extends Activity 
{
  Intent intent;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    /* 載入mylayout.xml Layout */
    setContentView(R.layout.myalyout);
     
     
    Button b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(new Button.OnClickListener()
    {
      public void onClick(View v)
      {
       /* 回傳result回上一個activity */
       Page1.this.setResult(RESULT_OK, intent);
        
       /* 關閉activity */
       Page1.this.finish();
      }
    });
  }
}

page2
package Demo;

/* import相關class */
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class Page2 extends Activity 
{
    
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    /* 載入main.xml Layout */
    setContentView(R.layout.main);
   
        /*new一個Intent物件,並指定class*/
     Intent intent = new Intent();
        intent.setClass(Page2.this,Page1.class);
     
     /*呼叫Activity EX03_11_1*/
     startActivityForResult(intent,0);
      }
  
  /* 覆寫 onActivityResult()*/
  @Override
  protected void onActivityResult(int requestCode, int resultCode,
                                  Intent data)
  {
    switch (resultCode)
    { 
      case RESULT_OK:
//回上一頁囉
        break;       
      default: 
        break; 
     } 
   } 
}