自由的程序员

生活是一场马拉松,学习亦是如此


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

css-元素垂直居中的6种方法

发表于 2016-09-26   |   分类于 Web , 开发知识 , Css

利用CSS进行元素的水平居中,比较简单,行级元素设置其父元素的text-align center,块级元素设置其本身的left 和 right margins为auto即可。本文收集了六种利用css进行元素的垂直居中的方法,每一种适用于不同的情况,在实际的使用过程中选择某一种方法即可。

1、Line-Height Method
适用:单行文本垂直居中

html代码:
<div id="parent">
    <div id="child">Text here</div>
</div>

css代码:
#child {
    line-height: 200px;
}

垂直居中一张图片

html代码:
<div id="parent">
    <img src="image.png" alt="" />
</div>

css代码:
#parent {
    line-height: 200px;
}
#parent img {
    vertical-align: middle;
}

2、CSS Table Method
适用:通用

html代码:
<div id="parent">
    <div id="child">Content here</div>
</div>

css代码:
#parent {
    display: table;
}
#child {
    display: table-cell;
    vertical-align: middle;
}

低版本 IE fix bug:
#child {
    display: inline-block;
}

3、Absolute Positioning and Negative Margin
适用:块级元素

html代码:
<div id="parent">
    <div id="child">Content here</div>
</div>

css代码:
#parent {
    position: relative;
}
#child {
    position: absolute;
    top: 50%;
    left: 50%;
    height: 30%;
    width: 50%;
    margin: -15% 0 0 -25%;

}

4、Absolute Positioning and Stretching
适用:通用,但在IE版本低于7时不能正常工作

html代码:
<div id="parent">
    <div id="child">Content here</div>
</div>

css代码:
#parent {
    position: relative;
}
#child {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 50%;
    height: 30%;
    margin: auto;
}

5、Equal Top and Bottom Padding
适用:通用

html代码:
<div id="parent">
    <div id="child">Content here</div>
</div>

css代码:
#parent {
    padding: 5% 0;
}
#child {
    padding: 10% 0;
}

6、Floater Div
适用:通用

html代码:
<div id="parent">
    <div id="floater">
</div>
<div id="child">Content here</div>
</div>

css代码:
#parent {
    height: 250px;
}
#floater {
    float: left;
    height: 50%;
    width: 100%;
    margin-bottom: -50px;
}
#child {
    clear: both;
    height: 100px;
}

以上就是六种方法,可以在实际的使用过程中合理选择。

Mac上安装oh-my-zsh

发表于 2016-09-22   |   分类于 Mac , Mac使用

GitHub地址

https://github.com/robbyrussell/oh-my-zsh

step1:克隆项目到本地(Mac默认已经安装了git)

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

step2:创建一个zsh的配置文件

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

step3:设置zsh为默认的shell

chsh -s /bin/zsh

step4:重启生效

打开一个新的终端窗口,大功告成。

Mac上设置Java环境变量

发表于 2016-09-22   |   分类于 Mac , Mac使用

说明

  1. 如果是用bash,修改~/.bash_profile或~/.profile。
    两者的区别:
    .bash_profile是用户级别的,更新系统或切换用户就会失效。
    .profile是系统级别的,永远都有效。
    2.如果是用zsh,修改~/.zshrc。

step1:检查是否安装了jdk(Mac系统默认已安装)

1.查看java的安装路径
which java
2.查看java版本
java -version

step2:设置环境变量

以bash为例:

## edit .bash_profile  to set java_home variable
vim ~/.bash_profile

## add the following line into the file
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home 
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

## let the configuration in .bash_profile take effect
source .bash_profile

以zsh为例:

## check all the available jdk
/usr/libexec/java_home -V

## check the top jdk
/usr/libexec/java_home

## check some jdk (eg. version 1.7)
/usr/libexec/java_home -v 1.7

## edit .zshrc to set java_home variable
vim ~/.zshrc

## add the following line into the file
export JAVA_HOME=$(/usr/libexec/java_home)

## you can also use the following line to set the variable, which is not         recommended, only for older mac os.
## export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

##let the configuration in .zshrc take effect
source ~/.zshrc

## check if configure succeed
echo $JAVA_HOME

Zsh使用

发表于 2016-09-22   |   分类于 Mac , Mac使用

使用默认指令列模式(bash shell)的管理员可能想仔细看看zshell或是zsh。由于它于bash相似,功能又有所加强,zsh在Linux社区获得了关注。
那么zsh有什么不同之处呢?首先,zsh在感觉和功能上都和bash相似。但是一些增强功能让zsh变成一个有趣的选择。
Zsh增强功能:标签完成和拼写错误修正

用过bash标签完成的管理员会发现zsh中的增加功能令人印象深刻。这些功能包括菜单中现有的自动完成命令选项,该菜单可以通过使用箭头键滚动。举例来说,键入以下命令将提供可能命令行标记的列表:
$ ls -或是
$ rm -选择要取消的特定程序,程序列表就和取消命令一起可用了。
另一个功能在内置页面程序中,它提供到less命令的快捷方式。要访问它,输入:
$ 这和在命令行上运行more文件名一样。
对笨拙的打字员来说,拼写错误修正功能可用了。例如,如果你输入了一条错误命令,zsh会提示修正:
$ llszsh: 要将 ‘lls’修改为 ‘ls’ [nyae]吗?
要修改它,输入y,命令就更正为ls,接着命令就准备运行了。
其它选项也很实用。输入n拒绝命令修正,输入a中断命令,输入e跳转到命令行进行编辑。这个自动修正功能也能用于命令行标记和文件名,包括修改无效Git分支名称一类的机密事务。
开始使用zsh

为了快速地开始使用zsh,可利用Robby Russell收集的zsh主题、功能和工具,它们被预先打包成“Oh My Zsh”。
$ wget –no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
还可以手工安装这个工具包。如果您在运行另一种 shell,只是想试试 Z shell,那么手工安装可能会更好。请使用 Git 复制这个工具包,然后运行 zsh:
$ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
$ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshr
c$ zsh
OMZ! 的默认主题称为 “robbyrussell”,由 OMZ! 的管理者命名。您可以将它更改为 ~/.oh-my-zsh/themes 中列出的任何主题。更改主题的方法是,打开 ~/.zshrc 文件,将 ZSH_THEME 变量设置为主题文件的基本名称。例如,要想使用 cloud.zsh-theme,则应该设置 ZSH_THEME=cloud。您可能会注意到,许多主题的输出状态信息显示在提示符中和提示符的最右边。 例如,Clean 主题在最右边输出当前时间。与硬件屏幕不同,屏幕模拟器的底部通常没有状态条,但是可以使用提示符右边的区域提供动态反馈。还记得可以在提示符中使用 \e[ 编码设置颜色吗?有一组这样的 “转义” 可以将光标移动到窗口中的不同位置。另外,目前的 UNIX 系统并没有使用神秘的符号和数字,而是使用 tput 按名称或用途查找和产生转义。Z shell 使用这种方法提供 RPS1 和 RPS2,它们分别表示初始行和后续行右边的提示符。
除了通过主题控制颜色和提示符之外,OMZ! 还提供了一些插件,这些插件将同类的函数和特性集中在一起。例如,如果您使用 Git 进行源代码控制,可以启用 Git OMZ! 插件,它会在提示符中增加 Git 状态。请打开 ~/.zshrc 文件,然后编辑插件行,在其中包含 git>。现在,当切换到一个 Git 存储库时,提示符会反映该状态。(极限shell改造)“Oh My Zsh”知识库包含一个主题和功能集合用于现有zsh环境的建立和改变。它也能和卸载脚本一起用来简化移除:
$ uninstall_oh_my_zsh
与zsh shell一起供给的还有一些很好的文档和zsh参考卡。GitHub等网站上的在线资源是.zshrc文件的例子,它相当于zsh版的.bashrc文件,这些资源同时也提供如何定制zsh的示例或是示范加强命令行经验的炫酷技巧。
一些zsh功能可和bash一起用,但在bash上设置、配置更加复杂,这也解释了为什么人们有多页.bashrc文件。如果是Shell的高度使用者,zsh会是吸引你用来取代bash的选择。它的使用快速且简单,而它的一些重要功能也让与shell的互动更有趣。
非常好用的特性
加强的 alias,在bash里如果你用 alias,新名不用有补全功能了,所以alias功能有限,几次想用它简化软件包管理都放弃了。而zsh里的alias生成的新名同样支持选项补全,就样就可以很放心地 alias ai=”sudo apt-get install” 等了,再也不用频繁输入长命令了。 zsh可以方便里使用快捷键,例如可以实现按两下[esc],在命令之前加加sudo,按[esc][h],显示man,等等。 zsh可以对单个命令的补全进行设置,使常用命令高效。例如 kill [tab] 就可以选择所有进程。 zsh的命令提示符设置更灵活。 zsh对目录的操作特别灵活。 zsh对重定向,管道等提供更多功能。
配置

#color{{{
    autoload colors zsh/terminfo
    if [[ "$terminfo[colors]" -ge 8 ]]; then
    colors
    fi
    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
    eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
    eval $color='%{$fg[${(L)color}]%}'
    (( count = $count + 1 ))
    done
    FINISH="%{$terminfo[sgr0]%}"
    #}}}

#命令提示符 {{{
    precmd () {
    local count_db_wth_char=$}}

#标题栏、任务栏样式{{{
    case $TERM in (*xterm*|*rxvt*|(dt|k|E)term)
    preexec () { print -Pn "\e]0;%n@%M//%/\ $1\a" }
    ;;
    esac
    #}}}

#关于历史纪录的配置 {{{
    #历史纪录条目数量
    export HISTSIZE=1000
    #注销后保存的历史纪录条目数量
    export SAVEHIST=1000
    #历史纪录文件
    export HISTFILE=~/.zhistory
    #以附加的方式写入历史纪录
    setopt INC_APPEND_HISTORY
    #如果连续输入的命令相同,历史纪录中只保留一个
    setopt HIST_IGNORE_DUPS
    #为历史纪录中的命令添加时间戳
    setopt EXTENDED_HISTORY

    #启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
    setopt AUTO_PUSHD
    #相同的历史路径只保留一个
    setopt PUSHD_IGNORE_DUPS

    #在命令前添加空格,不将此命令添加到纪录文件中
    #setopt HIST_IGNORE_SPACE
    #}}}


#杂项 {{{
    #允许在交互模式中使用注释 例如:
    #cmd #这是注释
    setopt INTERACTIVE_COMMENTS

    #启用自动 cd,输入目录名回车进入目录
    #稍微有点混乱,不如 cd 补全实用
    #setopt AUTO_CD

    #扩展路径
    #/v/c/p/p => /var/cache/pacman/pkg
    setopt complete_in_word

    #禁用 core dumps
    limit coredumpsize 0

    #Emacs风格 键绑定
    bindkey -e
    #设置 [DEL]键 为向后删除
    bindkey "\e[3~" delete-char

    #以下字符视为单词的一部分
    WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
    #}}}

#自动补全功能 {{{
    setopt AUTO_LIST
    setopt AUTO_MENU
    #开启此选项,补全时会直接选中菜单项
    #setopt MENU_COMPLETE

    autoload -U compinit
    compinit

    #自动补全缓存
    #zstyle ':completion::complete:*' use-cache on
    #zstyle ':completion::complete:*' cache-path .zcache
    #zstyle ':completion:*:cd:*' ignore-parents parent pwd

    #自动补全选项
    zstyle ':completion:*' verbose yes
    zstyle ':completion:*' menu select
    zstyle ':completion:*:*:default' force-list always
    zstyle ':completion:*' select-prompt '%SSelect: lines: %L matches: %M   [%p]'

    zstyle ':completion:*:match:*' original only
    zstyle ':completion::prefix-1:*' completer _complete
    zstyle ':completion:predict:*' completer _complete
    zstyle ':completion:incremental:*' completer _complete _correct
    zstyle ':completion:*' completer _complete _prefix _correct _prefix   _match _approximate

    #路径补全
    zstyle ':completion:*' expand 'yes'
    zstyle ':completion:*' squeeze-slashes 'yes'
    zstyle ':completion::complete:*' '\\'

    #彩色补全菜单
    eval $(dircolors -b)
    export ZLSCOLORS="${LS_COLORS}"
    zmodload zsh/complist
    zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
    zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-  9]#)*=0=01;31'

    #修正大小写
    zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
    #错误校正
    zstyle ':completion:*' completer _complete _match _approximate
    zstyle ':completion:*:match:*' original only
    zstyle ':completion:*:approximate:*' max-errors 1 numeric

    #kill 命令补全
    compdef pkill=killall
    zstyle ':completion:*:*:kill:*' menu yes select
    zstyle ':completion:*:*:*:*:processes' force-list always
    zstyle ':completion:*:processes' command 'ps -au$USER'

    #补全类型提示分组
    zstyle ':completion:*:matches' group 'yes'
    zstyle ':completion:*' group-name ''
    zstyle ':completion:*:options' description 'yes'
    zstyle ':completion:*:options' auto-description '%d'
    zstyle ':completion:*:descriptions' format $'\e[01;33m -- %d --\e[0m'
    zstyle ':completion:*:messages' format $'\e[01;35m -- %d --\e[0m'
    zstyle ':completion:*:warnings' format $'\e[01;31m -- No Matches Found --\e[0m'
    zstyle ':completion:*:corrections' format $'\e[01;32m -- %d (errors: %e) --\e[0m'

    # cd ~ 补全顺序
    zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path- directories' 'users' 'expand'
    #}}}

##行编辑高亮模式 {{{
    # Ctrl+@ 设置标记,标记和光标点之间为 region
    zle_highlight=(region:bg=magenta #选中区域
    special:bold #特殊字符
    isearch:underline)#搜索时使用的关键字
    #}}}

##空行(光标在行首)补全 "cd " {{{
    user-complete(){
    case $BUFFER in
    "" ) # 空行填入 "cd "
    BUFFER="cd "
    zle end-of-line
    zle expand-or-complete
    ;;
    "cd " ) # TAB + 空格 替换为 "cd ~"
    BUFFER="cd ~"
    zle end-of-line
    zle expand-or-complete
    ;;
    " " )
    BUFFER="!?"
    zle end-of-line
    ;;
    "cd --" ) # "cd --" 替换为 "cd +"
    BUFFER="cd +"
    zle end-of-line
    zle expand-or-complete
    ;;
    "cd +-" ) # "cd +-" 替换为 "cd -"
    BUFFER="cd -"
    zle end-of-line
    zle expand-or-complete
    ;;
    * )
    zle expand-or-complete
    ;;
    esac
    }
    zle -N user-complete
    bindkey "\t" user-complete

    #显示 path-directories ,避免候选项唯一时直接选中
    cdpath="/home"
    #}}}

##在命令前插入 sudo {{{
    #定义功能
    sudo-command-line() {
    [[ -z $BUFFER ]] && zle up-history
    [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
    zle end-of-line #光标移动到行末
    }
    zle -N sudo-command-line
    #定义快捷键为: [Esc] [Esc]
    bindkey "\e\e" sudo-command-line
    #}}}

#命令别名 {{{

    alias -g ls='ls -F --color=auto'
    alias -g ll='ls -l'
    alias -g la='ls -a'
    alias -g l='ls'
    alias -g grep='grep --color=auto'
    #alias -g history='history -fi'
    alias -g ai='sudo apt-get install'
    alias -g aar='sudo apt-get autoremove'
    alias -g ap='sudo apt-get purge'
    alias -g aud='sudo apt-get update'
    alias -g aug='sudo apt-get upgrade'
    alias -g adu='sudo apt-get dist-upgrade'

    #[Esc][h] man 当前命令时,显示简短说明
    alias run-help >&/dev/null && unalias run-help
    autoload run-help

    #历史命令 top10
    #alias top10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
    #}}}

#路径别名 {{{
    #进入相应的路径时只要 cd ~xxx
    hash -d HIST="$HISTDIR"
    #}}}

#{{{自定义补全
    #补全 ping
    zstyle ':completion:*:ping:*' hosts g.cn facebook.com
    #补全 ssh scp sftp 等
    my_accounts=(
    {ly50247,osily,lg50247,root}@{192.168.1.1,192.168.0.1}
    osily@localhost
    )
    zstyle ':completion:*:my-accounts' users-hosts $my_accounts

    #def pacman-color completion as pacman
    #compdef pacman-color=pacman
    #}}}

#{{{ F1 计算器
    arith-eval-echo() {
    LBUFFER="${LBUFFER}echo \$(( "
    RBUFFER=" ))$RBUFFER"
    }
    zle -N arith-eval-echo
    bindkey "^[[11~" arith-eval-echo
    #}}}

####{{{
    #function timeconv { date -d @$1 +"%Y-%m-%d %T" }

    # }}}

####{{{
    function command_not_found_handler() {
    python /usr/lib/command-not-found $1
    return 0
    }
    # }}}

## END OF FILE   #################################################################
# vim:filetype=zsh foldmethod=marker autoindent expandtab   shiftwidth=4


export http_proxy=http://192.168.187.145:80
#export JAVA_HOME="/usr/lib/jvm/java-6-sun"
#export JRE_HOME="/usr/lib/jvm/java-6-sun/jre"
export PATH="$PATH:/home/osily/program/bin"
#exportCLASSPATH="$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/li b:/home/osily/program/tomcat620/lib:/home/osily/program/tomcat620/lib/servlet-api.jar"
alias upg="sudo apt-get update && sudo apt-get upgrade"
alias qq="nohup google-chrome --no-proxy-server --  app=http://web.qq.com >/dev/null 2>/dev/null &"
#alias tomstart="sudo ~/program/tomcat620/bin/startup.sh"
#alias tomshut="sudo ~/program/tomcat620/bin/shutdown.sh"
#alias js2="rhino"
alias gmusic="google-chrome --no-proxy-server --  app=http://g.top100.cn/12174704/html/player.html#loaded"
alias apa="dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P"

Mac上如何完全删除node.js

发表于 2016-09-22   |   分类于 Mac , Mac使用
  1. 删除/usr/local/lib中的所有node和node_modules
  2. 删除/usr/local/lib中的所有node和node_modules的文件夹
  3. 如果是从brew安装的, 运行brew uninstall node
  4. 检查~/中所有的local, lib或者include文件夹, 删除里面所有node和node_modules
  5. 在/usr/local/bin中, 删除所有node的可执行文件
  6. 最后运行以下代码:

    sudo rm /usr/local/bin/npm
    sudo rm /usr/local/share/man/man1/node.1
    sudo rm /usr/local/lib/dtrace/node.d
    sudo rm -rf ~/.npm
    sudo rm -rf ~/.node-gyp
    sudo rm /opt/local/bin/node
    sudo rm /opt/local/include/node
    sudo rm -rf /opt/local/lib/node_modules

Mac上安装Homebrew及常用命令

发表于 2016-09-22   |   分类于 Mac , Mac使用

Homebrew简称brew 。

是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 使用命令,非常方便。

安装Homebrew

在Mac中打开Termal: 输入命令:
ruby -e “$(curl –insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

使用brew安装软件

比如安装git:
brew install git

使用brew卸载软件

brew uninstall git

使用brew查询软件

brew search /gi*/

/gi*/是个正在表达式。

其他brew命令

brew list:列出已安装的软件

brew update:更新brew

brew home:用浏览器打开brew的官方网站

brew info:显示软件信息

brew deps:显示包依赖

常用Atom插件列表(持续更新...)

发表于 2016-09-22   |   分类于 Web , 开发工具 , Atom
  • 1、simplified-chinese-menu
  • 2、tree-view-finder
  • 3、minimap
  • 4、linter和linter-jshint
  • 5、linter-js-standard
  • 6、git-plus
  • 7、file-types和file-types-icon
  • 8、emmet
  • 9、autoclose-html
  • 10、atom-ternjs
  • 11、atom-html-preview
  • 12、atom-bootstrap3
  • 13、Remote-FTP
  • 14、autocomplete-paths
  • 15、atom-beautify
  • 16、jquery-snippets
  • 17、autoprefixer
  • 18、color-picker
  • 19、activate-power-mode
1、simplified-chinese-menu

Atom的简体中文语言包,完整汉化,兼容所有已发布的版本Atom。

2、tree-view-finder

左边菜单栏显示方式,类似Mac OS下的finder。
01.tree-view-finder

3、minimap

类似sublim text右边的代码缩略图。

4、linter和linter-jshint

该插件是用jshint来检查代码,想必大家都听说过jshint代码检查工具,它有一个配置文件.jshintrc,这个文件告诉jshint执行的检查规则。通过jshint能发现代码中存在的问题,可以及时避免bug的发生。linter-jshint插件基于atom规则来使用jshint,该插件可以在项目根目录下新建一个.jshintrc来告诉检查规则,也可以不用创建此文件来进行代码检查。
注意:linter-jshint是依赖linter插件来使用的,也就是说必须先安装linter插件;因为linter是一个粗糙的检查,有很多针对专门项的代码检查,如linter-csslint、linter-php等等
02.linter和linter-jshint

5、linter-js-standard

用来使javascript代码格式化。

6、git-plus

提供git版本控制操作的命令,个人感觉不是很好用,还是terminal比较习惯。

7、file-types和file-types-icon

file-types用来区分文件类型的,file-types-icon用来给不同的问题类型添加不同的图标。
03.file-types和file-types-icon

8、emmet

这款插件是用来支持zend-coding,Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生。它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度

9、autoclose-html

html标签自动比较。

10、atom-ternjs

该插件能对一个对象中拥有的对外提供的属性和方法都能通过suggest的形式提示出来,能对一个对象对外提供的接口有一个选择过程,可以理解为js代码自动提示。

11、atom-html-preview

html页面预览。

12、atom-bootstrap3

bootstrap3代码提示插件。

13、Remote-FTP

ftp管理工具,命令和图形化界面都支持。
13.Remote-FTP
PS:具体使用方式,参考官方说明或留言。

14、autocomplete-paths

文件路径自动提示。
14、autocomplete-paths

15、atom-beautify

代码格式化。
15、atom-beautify

16、jquery-snippets

jquery代码提示,安装完之后要重新启动Atom。

17、autoprefixer

浏览器兼容。
17、autoprefixer

18、color-picker

取色器。
18、color-picker

19、activate-power-mode

代码在跳舞
19、activate-power-mode

css-如何规定某一元素高度等于其宽度

发表于 2016-09-22   |   分类于 Web , 开发知识 , Css

使用js实现

<script type="text/javascript">
    $(document).ready(function(){
    $('#box1').css('height',$('#box1').css('width'));
})
</script>
<style type="text/css">
#box{
    width: 900px;
    height: 400px;
    border:1px solid red;
}
#box1{
    width:50%;
    border:1px solid green;
}
</style>
<body>
<div id='box'>
<div id='box1'></div>
</div>
</body>

Ps:如果还有其他实现方式,请留言,谢谢。

Android Studio常用插件列表(持续更新...)

发表于 2016-09-22   |   分类于 Android , 开发工具 , Android Studio

引言

工欲善其事,必先利其器!作为一名苦逼的程序员,提高开发效率,可以使用节约的时间做其他事情。

1、.ignore

在Git 中想要过滤掉一些不想提交的文件,可以把相应的文件添加到.gitignore 中,而.gitignore 这个Android Studio 插件根据不同的语言来选择模板,就不用自己在费事添加一些文件了,而且还有自动补全功能,过滤文件再也不要复制文件名了。没有ignore file 可以右键项目New 出自动生成上面模板的 ignore file,已有ignore file 的话可以右键文件选择Add template…,也可以右键将向忽略的文件直接添加到ignore file 里。

2、Android ButterKnife Zelezny

ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及 setOnClickListener代码,可视化一键生成。
2、Android ButterKnife Zelezny

3、Android Parcelable code generator

快速实现Parcelable接口的插件。
3、Android Parcelable code generator

4、Android Postfix Completion

可根据后缀快速完成代码。
4、Android Postfix Completion

5、Codota

该网站搜集了大量的代码,号称超过700W的代码实例。提供了chrome和as插件。

6、Dash

Dash是一个API文档浏览器( API Documentation Browser),以及代码片段管理工具(Code Snippet Manager)。安装此插件后,可以打开Dash客户端,如果Dash里多个API文档,默认打开Android。很多IDE都支持Dash,只要安装相应的插件即可。
6、Dash

7、DataBase Navigator

轻量级的,在Android Studio中使用的数据库可视化插件。
7、DataBase Navigator_573.jpg)

8、GsonFormat

GsonFormat是一个快速格式化json数据,自动生成实体类参数的插件。
8、GsonFormat

9、Lifecycle Sorter

可以根据Activity或者fragment的生命周期对其生命周期方法位置进行先后排序。
9、Lifecycle Sorter

10、Markdown

Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式。

11、 Android Drawable Importer

为了适应所有Android屏幕的大小和密度,每个Android项目都会包含drawable文件夹。任何具备Android开发经验的开发人员都知道,为了支持所有的屏幕尺寸,你必须给每个屏幕类型导入不同的画板。Android Drawable Importer插件能让这项工作变得更容易。它可以减少导入缩放图像到Android项目所需的工作量。Android Drawable Importer添加了一个在不同分辨率导入画板或缩放指定图像到定义分辨率的选项。这个插件加速了开发人员的画板工作。

参考使用地址:http://blog.csdn.net/ziwang_/article/details/51713623

12、Material Design Icon Generator

一款帮助我们设置Material风格图标的插件

13、SelectorChapek for Android

根据资源自动生成相应的selector。

14、JavaDoc

添加注释,可自定义模板。

15、Android Holo Colors Generator

通过自定义Holo主题颜色生成对应的Drawable和布局文件

16、Android strings.xml tools

可以用来管理Android项目中的字符串资源。它提供了排序Android本地文件和添加缺少的字符串的基本操作。虽然这个插件是有限制的,但如果应用程序有大量的字符串资源,那这个插件就非常有用了。

17、lint-cleaner-plugin

删除未使用的资源,包括String字符串,颜色和尺寸。 这是一个Gradle插件,所以如何配置可以去github的源码上看。
插件源码地址:https://github.com/marcoRS/lint-cleaner-plugin

18、 Material Theme UI

This will add the Material Theme look to your IDE.

18、Material Theme UI

19、Key pomoter

Shows to user how easy he can make same action using only keyboard(menus and toolbar button mouse clicks initiates shortcut display)
简单来说,就是执行操作后,提示对应操作的快捷键,可以帮助记忆快捷键。

20、ECTranslation

翻译插件,可以再IDE里直接翻译单词,方便很多。

Android-使用Intent打开各种文件

发表于 2016-09-22   |   分类于 Android , 开发知识 , Other

1、打开Html文件

public static Intent getHtmlFileIntent( String param )  {   
     Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build();    
     Intent intent = new Intent("android.intent.action.VIEW");   
     intent.setDataAndType(uri, "text/html");    
     return intent;  
}

2、打开图片文件

public static Intent getImageFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "image/*");    
    return intent;  
}

3、打开pdf文件

public static Intent getPdfFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "application/pdf");    
    return intent; 
}

4、打开txt文件

public static Intent getTextFileIntent( String paramString, boolean paramBoolean) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    if (paramBoolean) {      
        Uri uri1 = Uri.parse(param );      
        intent.setDataAndType(uri1, "text/plain");    
    }   
    while (true) {      
        return intent;      
        Uri uri2 = Uri.fromFile(new File(param ));     
        intent.setDataAndType(uri2, "text/plain");    
    }  
}

5、打开音频文件

public static Intent getAudioFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);    
    intent.putExtra("oneshot", 0);    
    intent.putExtra("configchange", 0);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "audio/*");    
    return intent;  
}

6、打开视频文件

public static Intent getVideoFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);    
    intent.putExtra("oneshot", 0);    
    intent.putExtra("configchange", 0);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "video/*");    
    return intent;  
}

7、打开chm文件

public static Intent getChmFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "application/x-chm");    
    return intent;  
}

8、打开word文件

public static Intent getWordFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "application/msword");    
    return intent;  
}

9、打开Excel文件

public static Intent getExcelFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "application/vnd.ms-excel");    
    return intent;  

}

10、打开ppt文件

public static Intent getPptFileIntent( String param ) {    
    Intent intent = new Intent("android.intent.action.VIEW");    
    intent.addCategory("android.intent.category.DEFAULT");    
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
    Uri uri = Uri.fromFile(new File(param ));    
    intent.setDataAndType(uri, "application/vnd.ms-powerpoint");    
    return intent;  
}

Ps:参考资料

  1. 关于Intent的七大属性
  2. Android中Intent概述及使用
  3. Android Intent Action 大全
123
妞妞骑毛驴

妞妞骑毛驴

Android、Java、Mac、Web、版本控制

22 日志
21 分类
17 标签
GitHub
© 2015 - 2016 妞妞骑毛驴
由 Hexo 强力驱动
主题 - NexT.Pisces