其实图片在android 中的应用都是integer的id
<resources>
<integer-array name="bottom_list">
<item>@mipmap/perm_group_messagesitem>
<item>@mipmap/perm_group_phone_callsitem>
<item>@mipmap/perm_group_system_clockitem>
<item>@mipmap/perm_group_system_toolsitem>
<item>@mipmap/perm_group_accountsitem>
integer-array>
resources>
java代码获取
TypedArray imgs = getResources().obtainTypedArray(R.array.bottom_list);
for (int i = 0; i < imgs.length(); ++i) {
// index ,defaultValue
int drawableResId = imgs.getResourceId(i,R.mipmap.perm_group_system_tools);
}
imgs.recycle();
image.setImageResource(drawableResId);
利用查表法,和随机数法
// 定义字符数组
private static char[] chars = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N','O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
//获取随机字符串
public static String getRandomString() {
Random random = new Random();
//获取随机长度
int length = random.nextInt(chars.length) + 1;
char[] data = new char[length];
for (int i = 0; i < length; i++) {
//获取随机字符
int index = random.nextInt(chars.length);
data[i] = chars[index];
}
return new String(data);
}
和我们写md博客添加图片类似,前面需要加上![],中括号内是描述,()内是url地址和 别名
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary
- "colorPrimaryDark"
>@color/colorPrimaryDark
- "colorAccent">@color/colorAccent
style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">falseitem>
--是否显示title-->
<item name="windowNoTitle">trueitem>
style>
<style name="AppTheme.NoActionBar.Trans">
--是否浮现在activity之上-->
<item name="android:windowIsFloating">trueitem>
--Window 的背景-->
<item name="android:windowBackground">@android:color/transparent
- "android:windowIsTranslucent"
>true
- "android:windowAnimationStyle">@android:style/Animation.Translucent
- "android:windowContentOverlay">@null
- "android:backgroundDimEnabled">false
style>
resources>
在Manifest中添加theme
<activity
android:name=".SencondActivity"
android:theme="@style/AppTheme.NoActionBar.Trans" />
在启动应用的时候,首个activity会做一些初始化操作,就会导致有一个黑屏的时期或者过渡不自然。通过上面theme的方式就可以很巧妙的避免这一点
<style name="AppTheme.NoActionBar.NoDisplay" parent="@android:Theme">
<item name="android:windowBackground">@null
- "android:windowContentOverlay"
>@null
- "android:windowIsTranslucent"
>false
- "android:windowAnimationStyle">@null
- "android:windowDisablePreview">true
- "android:windowNoDisplay">false
style>
<activity
android:name=".SencondActivity"
android:theme="@style/AppTheme.NoActionBar.NoDisplay" />
这是一种不显示的方式。也就是取消默认的window preview
还有一种设置启动图片的方式
<style name="AppTheme.NoActionBar.CustomBackground" >
--显示loading的图片-->
<item name="android:windowBackground">@drawable/loading
- "android:windowNoTitle"
>true
- "android:windowFullscreen">true
- "android:windowContentOverlay">@null
style>
command+space
打开terminal.app
,输入 cd ~
touch .bash_profile
回车,这个命令是 创建或者 更新.bash_profile
文件open -e .bash_profile
,打开.bash_profile
文件export PATH=${PATH}:/Users/bobomee/Library/Android/sdk/platform-tools
其中/Users/bobomee/Library/Android/sdk/为sdk路径。
标题和菜单是acationBar的一部分,所以首先定义ActionBar的样式style
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/CustomActionBar
style>
然后在ActionBar的样式中通过android:titleTextStyle
定义标题的样式
副标题文字样式可以通过android:subtitleTextStyle
来指定
菜单的样式,比如在Light主题下,想要menu的文字颜色是白色的,怎么做呢?
需要指定属性android:actionMenuTextColor
ps:
-- Base application theme. -->
在ScrollView中嵌套的子View获取焦点或者布局改变的时候会自动滚动到焦点View,针对这个问题,我们可以这样解决
focus
view.setFocusable(false)
;scrollto(0,0)
或者重写ScrollView中的computeScrollDeltaToGetChildRectOnScreen
,让该方法返回0
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
return 0;
}
【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
其后在github上看到了xesam/CenterDrawableTextView,可以直接使用,非常方便
经常有这样的需求,在密码输入框的后面,为了让用户看到输入的内容,这是会显示一个小眼睛在输入框的后面,用于明文或者密文显示
//password明文密文切换
public static void visible(EditText editText, boolean show) {
editText.setTypeface(Typeface.DEFAULT);
editText.setTransformationMethod(show ? HideReturnsTransformationMethod.getInstance()
: PasswordTransformationMethod.getInstance());
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
editText.setSelection(start, end);
}
我们知道给ListView
设置HeaderView
必须在setAdapter
之前,这时候可以通过LayoutParams设置HeaderView的宽高.但是如果设置为0,则会转变为wrap_content
正确的做法是通过代码添加一层View来包裹HeaderView,之后就可以设置了
LinearLayout mWrapper1 = new LinearLayout(activity);
mDivider = LayoutInflater.from(activity)
.inflate(R.layout.list_divider_layout, mWrapper1, false);
mWrapper1.addView(mDivider);
listView.addHeaderView(mWrapper1);
//set layoutparams
LinearLayout.LayoutParams dividerParams =
new LinearLayout.LayoutParams(w, 0);
mDivider.setLayoutParams(dividerParams);
参考:AbsListView的Header不能直接固定大小为0