TextView设置字体:
1: assets下防止字体的文件
2: Typeface type = Typeface.createFromAsset(getResources().getAssets(),"文件名字");
3: TextView.setTypeface(type);
Android Studio:设置左边栏的颜色
在Settings窗口选择appearance & Behavior,再选择File Colors,在右边选择+号,Scope选择Project Files,并选择Custom自己喜欢的颜色就OK了
gravity无效,view的height和width的大小有关
seekbar几个需要注意的问题:
(1)自定义的滑块滑动到边缘时要是中心处于边缘位置,那么会有一部分滑块超出长条边缘,这时要指定paddingleft和paddingright,不然不能显示超出部分的滑块。
(2)滑块滑到边缘时,还有可能中心位置并不是恰好处于边缘,这时候要指定thumbOffset属性,长度为滑块宽的一半,那样就能显示好了。
(3)长条宽度是通过maxHeight指定,使用其它方法指定宽度不行,不影响滑块的。
在安卓开发中遇到conn.getResponseCode()==200抛出异常,主要是因为在安卓4.0以上的版本不支持主线程连接服务器,可以另起一个线程来用于与服务器连接,也可以用以下方法解决,还可以通过安卓开源框架Android-async-http进行与服务器的交互
1:首先查看配置文件,在里面加入网络权限
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
2:在MainActivity.Java中加入以下代码,放在onCreate()方法体里面
StrictMode.setThreadPolicy(new
StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(
new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
3:将android:minSdkVersion设置为11
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
在Android studio导入新的项目时,出现如下问题:
“Error:Could not determine the class-path for interface com.android.builder.model.NativeAndroidProjec"
在library项目上,右键,选择"open module settings" ->出现"project Structure"对话框 -> 选中"project"->修改右边的"Gradle Version“为当前使用的gradle版本。
在gradle文件夹下的gradle-wrapper.properties中将distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip的路径写对
6.7
<requestFocus
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true"/>
在widget的TextView中加入这个标签可实现跑马灯效果
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient android:startColor="@color/primary_dark"
android:endColor="@android:color/transparent"
android:angle="90"
/>
</shape>
</item>
</selector>
渐变,
动态添加selector:
public StateListDrawable setStateDrawable(int normal, int pressed, int selected,View view)
{
Resources res = mContext.getResources();
StateListDrawable sd = new StateListDrawable();
Drawable iNormal = normal <=0 ? null : res.getDrawable(normal);
Drawable iPressed = pressed <=0 ? null : res.getDrawable(pressed);
Drawable iSelected = selected <=0 ? null : res.getDrawable(selected);
// 注意该处的顺序,只要有一个状态与之相配,背景就会被换掉
// 所以不要把大范围放在前面了,如果sd.addState(new[]{},normal)放在第一个的话,就没有什么效果了
sd.addState(new int[] { android.R.attr.state_selected }, iSelected);
sd.addState(new int[] { android.R.attr.state_pressed }, iPressed);
sd.addState(new int[] { android.R.attr.state_enabled }, iNormal);
sd.addState(new int[] {}, iNormal);
// view.setBackground(sd);
return sd;
}
uninstall