当前位置:首页 » 安卓系统 » 自定义android系统

自定义android系统

发布时间: 2022-08-04 12:30:36

㈠ 如何自定义android Button样式

在windows7操作系统Android studio中按照如下方法定义button的样式。

1、首先使用Android studio创建一个项目,项目结构如下:

㈡ 如何在Android开发中使用自定义的字体库

1、Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace
2、在Android中可以引入其他字体 。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:Android="http://schemas.android.com/apk/res/android"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent" >

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="sans:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的sans字体 -->

<TextView
Android:id="@+id/sans"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="sans" >
</TextView>
</TableRow>

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="serif:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的serifs字体 -->

<TextView
Android:id="@+id/serif"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="serif" >
</TextView>
</TableRow>

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="monospace:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的monospace字体 -->

<TextView
Android:id="@+id/monospace"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="monospace" >
</TextView>
</TableRow>
<!-- 这里没有设定字体,我们将在Java代码中设定 -->

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="custom:"
Android:textSize="20sp" >
</TextView>

<TextView
Android:id="@+id/custom"
Android:text="Hello,World"
Android:textSize="20sp" >
</TextView>
</TableRow>

</TableLayout>
// 得到TextView控件对象
TextView textView = (TextView) findViewById(R.id.custom);
// 将字体文件保存在assets/fonts/目录下,www.linuxidc.com创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/DroidSansThai.ttf");
// 应用字体
textView.setTypeface(typeFace);
如果想对整个界面的所有控件都应用自定义字体,可以:

package arui.blog.csdn.NET;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FontManager {
public static void changeFonts(ViewGroup root, Activity act) {
Typeface tf = Typeface.createFromAsset(act.getAssets(),
"fonts/xxx.ttf");
for (int i = 0; i < root.getChildCount(); i++) {
View v = root.getChildAt(i);
if (v instanceof TextView) {
((TextView) v).setTypeface(tf);
} else if (v instanceof Button) {
((Button) v).setTypeface(tf);
} else if (v instanceof EditText) {
((EditText) v).setTypeface(tf);
} else if (v instanceof ViewGroup) {
changeFonts((ViewGroup) v, act);
}
}
}
}

㈢ 如何重写android系统sn

自定义progressbar
现在要自定义一个等待的时候转动的小圈,相信大家也都嫌系统自带的很麻烦吧??
如果要自定义那些系统的组件都有一个法子,那就是看系统的是怎么写的。
看下系统的progressbar的方法:
首先看android的系统的style.xml的文件,系统的样式定义都在里面 android-sdk-windows\platforms\android-8\data\res\values 目录下打开style.xml,搜索ProgressBar。
可以看到系统是这样定义progressbar的:
<style name="Widget.ProgressBar">
<item name="android:indeterminateOnly">true</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:indeterminateDuration">3500</item>
<item name="android:minWidth">48dip</item>
<item name="android:maxWidth">48dip</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>
接下来我们关注下 <item name="android:indeterminateDrawable">@android:drawable/progress_medium_white</item> 这一行。可以看到它使用了android:drawable/progress_medium_white这样的一个资源
找到这个文件并且打开,我们可以看到:
<?xml version="1.0" encoding="utf-8" ?>
- <!-- /*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

-->
<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_white_48" android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
我把前面的注释去掉,大家再看:
<?xml version="1.0" encoding="utf-8" ?>
<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_white_48"
android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
就剩这么多了,然后分析下这个文件(总共没有几行代码了嘛)
xmlns:android="http://schemas.android.com/apk/res/android" 约束,不说了,也不需要我们关注
android:drawable="@drawable/spinner_white_48" 这个相信接触过android的都知道这是指定了一个图标吧
android:pivotX="50%"
android:pivotY="50%" 这两行代码是指定了一个点(point嘛)那是什么点呢,中心点,我们让那个圆圈围着这个点转动,就有了动画效果,所以它是指定的围绕哪个点转动(为了证明我的猜想,我在后来自定义的代码中将他们都改成了0,它们就围

㈣ 如何为android4.2手机系统添加自定义的新字体

首先将自定义字体放到“assets”下面被实例化之后再使用,如果你的DDMS中的system/fonts/....下面有你需要的ttf文件的话,
可以直接使用下面的方法来调用
在程序中通过如下方式实例化自定义字体:
Java代码 :Typeface.createFromAsset(getContext().getAssets(), "fonts/samplefont.ttf");
下面是Android默认字体和自定义字体的绘制效果:
源代码如下:
Java代码:
package com.yarin.android.Typefaces;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
public class Typefaces extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View
{
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Typeface mFace;
public SampleView(Context context)
{
super(context);
//实例化自定义字体
mFace = Typeface.createFromAsset(getContext().getAssets(), "fonts/samplefont.ttf");
//设置字体大小
mPaint.setTextSize(32);
}
@Override protected void onDraw(Canvas canvas)
{
canvas.drawColor(Color.WHITE);
//绘制默认字体
mPaint.setTypeface(null);
canvas.drawText("Default:abcdefg", 10, 100, mPaint);
//绘制自定义字体
mPaint.setTypeface(mFace);
canvas.drawText("Custom:abcdefg", 10, 200, mPaint);
}
}
}好了,就这么简单就实现了自定义字体。
下面是两个非常有用的方法,在这里备份一下:
Java代码://消除锯齿
paint.setFlags(Paint.ANTI_ALIAS_FLAG)
//取得字符串宽度
paint.measureText()

㈤ 如何系统的学习android自定义各种酷炫控件

首先,为什么需要自定义View?

1. 现有的View满足不了你的需求,也没有办法从已有控件派生一个出来;界面元素需要自己绘制。
2. 现有View可以满足要求,把它做成自定义View只是为了抽象:为这个自定义View提供若干方法,方便调用着操纵View。通常做法是派生一个已有View,或者结合xml文件直接inflate。

目前常用的基本上是第二种方式,这种方式非常简单,与通常的View使用方法基本相同,但是作用却异常强大,拥有了这一层抽象,代码更加整洁也更容易维护,通过抽取自定义View的公共操作方法也减少了冗余代码,虽然简单,但不可忽视。

大多数人感觉神秘的应该是第一种,自绘控件,完全自定义;但其实这两种方式归根结底全部都是自绘;不信你去看看TextView的源码。只不过通常情况下系统帮我们绘制好了一些控件给开发者使用;OK,接下来就是一个问题。

在讲述之前我还是啰嗦地重申一下,复用已有View是最最常用也最有效的自定义View方式,必须熟练使用。

其次,如何自定义View?

想一下,一个View给用户最直观的感知是什么?静止的形态和动态的操作。静止的形态意思就是一个View呈现到用户眼里长成啥样子?动态操作指的是,用户与View之间可以有哪些交互?点击滑动View的不同地方会有什么反应?

1. 静态

如果一个自定义View的样式都没有办法绘制出来,那么后续的交互就是空谈了;我们一步步分解这个问题。

1.1 你的自定义View分为哪几个部分?是所有的部分都需要手动绘制还是只有一部分——找出需要完全自定义的部分,其他的部分用已有View实现。

1.2 你的自定义View的每个部分长成什么样,占用多大空间——结合理论知识View的measure过程,比如match_parent, wrap_content结合父View的laout_params参数最终测量大小是多少?

1.3 你的自定义View每个部分摆放在哪?相对位置如何?——View的layout过程。

1.4 你的自定义View那些完全需要手动绘制的部分是什么样,如何绘制?

你得学会操纵Canvas,学会2D绘图,什么?你跟我说3D,OpenGL?学会这些再说。

㈥ android 系统属性怎么定义

对于自定义属性,大家肯定都不陌生,遵循以下几步,就可以实现:

自定义一个CustomView(extends View )类
编写values/attrs.xml,在其中编写styleable和item等标签元素
在布局文件中CustomView使用自定义的属性(注意namespace)
在CustomView的构造方法中通过TypedArray获取
ps:如果你对上述几个步骤不熟悉,建议先熟悉下,再继续~
那么,我有几个问题:

以上步骤是如何奏效的?
styleable 的含义是什么?可以不写嘛?我自定义属性,我声明属性就好了,为什么一定要写个styleable呢?
如果系统中已经有了语义比较明确的属性,我可以直接使用嘛?
构造方法中的有个参数叫做AttributeSet
(eg: MyTextView(Context context, AttributeSet attrs) )这个参数看名字就知道包含的是参数的数组,那么我能不能通过它去获取我的自定义属性呢?
TypedArray是什么鬼?从哪冒出来的,就要我去使用?
恩,针对这几个问题,大家可以考虑下,如何回答呢?还是说:老子会背上述4个步骤就够了~~

2、常见的例子

接下来通过例子来回答上述问题,问题的回答顺序不定~~大家先看一个常见的例子,即上述几个步骤的代码化。

㈦ android自定义控件怎么用

一、控件自定义属性介绍
以下示例中代码均在values/attrs.xml 中定义,属性均可随意命名。
1. reference:参考某一资源ID。
示例:
<declare-styleable name = "名称">

<attr name = "background" format = "reference" />
<attr name = "src" format = "reference" />
</declare-styleable>

2. color:颜色值。
示例:
<declare-styleable name = "名称">

<attr name = "textColor" format = "color" />
</declare-styleable>

3. boolean:布尔值。
示例:
<declare-styleable name = "名称">

<attr name = "focusable" format = "boolean" />
</declare-styleable>

4. dimension:尺寸值。
示例:
<declare-styleable name = "名称">

<attr name = "layout_width" format = "dimension" />
</declare-styleable>

5. float:浮点值。
示例:
<declare-styleable name = "名称">

<attr name = "fromAlpha" format = "float" />
<attr name = "toAlpha" format = "float" />
</declare-styleable>

6. integer:整型值。
示例:
<declare-styleable name = "名称">

<attr name = "frameDuration" format="integer" />
<attr name = "framesCount" format="integer" />
</declare-styleable>

7. string:字符串。
示例:
<declare-styleable name = "名称">

<attr name = "text" format = "string" />
</declare-styleable>

8. fraction:百分数。
示例:

<declare-styleable name="名称">
<attr name = "pivotX" format = "fraction" />
<attr name = "pivotY" format = "fraction" />
</declare-styleable>

9. enum:枚举值。
示例:
<declare-styleable name="名称">

<attr name="orientation">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
</declare-styleable>

10. flag:位或运算。
示例:
<declare-styleable name="名称">

<attr name="windowSoftInputMode">
<flag name = "stateUnspecified" value = "0" />
<flag name = "stateUnchanged" value = "1" />
<flag name = "stateHidden" value = "2" />
<flag name = "stateAlwaysHidden" value = "3" />
</attr>
</declare-styleable>

11.多类型。
示例:

<declare-styleable name = "名称">
<attr name = "background" format = "reference|color" />
</declare-styleable>

二、属性的使用以及自定义控件的实现
1、构思控件的组成元素,思考所需自定义的属性。
比如:我要做一个 <带阴影的按钮,按钮正下方有文字说明>(类似9宫格按钮)
新建values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="custom_view">
<attr name="custom_id" format="integer" />
<attr name="src" format="reference" />
<attr name="background" format="reference" />
<attr name="text" format="string" />
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
</declare-styleable>
</resources>

以上,所定义为custom_view,custom_id为按钮id,src为按钮,background为阴影背景,text为按钮说明,textColor为字体颜色,textSize为字体大小。

2、怎么自定义控件呢,怎么使用这些属性呢?话不多说请看代码,CustomView :

package com.nanlus.custom;
import com.nanlus.custom.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomView extends FrameLayout implements OnClickListener {
private CustomListener customListener = null;
private Drawable mSrc = null, mBackground = null;
private String mText = "";
private int mTextColor = 0;
private float mTextSize = 20;
private int mCustomId = 0;
private ImageView mBackgroundView = null;
private ImageButton mButtonView = null;
private TextView mTextView = null;
private LayoutParams mParams = null;
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.custom_view);
mSrc = a.getDrawable(R.styleable.custom_view_src);
mBackground = a.getDrawable(R.styleable.custom_view_background);
mText = a.getString(R.styleable.custom_view_text);
mTextColor = a.getColor(R.styleable.custom_view_textColor,
Color.WHITE);
mTextSize = a.getDimension(R.styleable.custom_view_textSize, 20);
mCustomId = a.getInt(R.styleable.custom_view_custom_id, 0);
mTextView = new TextView(context);
mTextView.setTextSize(mTextSize);
mTextView.setTextColor(mTextColor);
mTextView.setText(mText);
mTextView.setGravity(Gravity.CENTER);
mTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView = new ImageButton(context);
mButtonView.setImageDrawable(mSrc);
mButtonView.setBackgroundDrawable(null);
mButtonView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView.setOnClickListener(this);
mBackgroundView = new ImageView(context);
mBackgroundView.setImageDrawable(mBackground);
mBackgroundView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addView(mBackgroundView);
addView(mButtonView);
addView(mTextView);
this.setOnClickListener(this);
a.recycle();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mParams = (LayoutParams) mButtonView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mButtonView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mBackgroundView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mBackgroundView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mTextView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
mTextView.setLayoutParams(mParams);
}
}
public void setCustomListener(CustomListener l) {
customListener = l;
}
@Override
public void onClick(View v) {
if (customListener != null) {
customListener.onCuscomClick(v, mCustomId);
}
}
public interface CustomListener {
void onCuscomClick(View v, int custom_id);
}
}
代码很简单,就不多说,下面来看看我们的CustomView是怎么用的,请看:

3、自定义控件的使用
话不多说,请看代码,main.xml:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<com.nanlus.custom.CustomView
android:id="@+id/custom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
nanlus:background="@drawable/background"
nanlus:custom_id="1"
nanlus:src="@drawable/style_button"
nanlus:text="按钮1" >
</com.nanlus.custom.CustomView>
</LinearLayout>
</RelativeLayout>

在这里需要解释一下,
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
nanlus为在xml中的前缀,com.nanlus.custom为包名

4、在Activity中,直接上代码
package com.nanlus.custom;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nanlus.BaseActivity;
import com.nanlus.custom.R;
import com.nanlus.custom.CustomView.CustomListener;
public class CustomActivity extends BaseActivity implements CustomListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((CustomView) this.findViewById(R.id.custom1)).setCustomListener(this);
}
@Override
public void onCuscomClick(View v, int custom_id) {
switch (custom_id) {
case 1:
Toast.makeText(this, "hello !!!", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}

㈧ android开发者:修改android图标ic_launcher,为自定义的.

android图标ic_launcher的修改方式:

  1. 将自定义的图片复制到 res/drawable目录下,例如 logo.png.

  2. 打开AndroidManifest.xml文件.

  3. 在application节点中修改android:icon为android:icon="@drawable/logo"即可.

注意,部分Android手机的桌面有缓存,改了icon以后,桌面应用图标并没有变,需要重启手机才会生效.

热点内容
at24c02存储芯片的参考文献 发布:2024-05-22 07:28:26 浏览:727
微信apiphp 发布:2024-05-22 07:26:49 浏览:148
编译kernel的流程 发布:2024-05-22 07:26:47 浏览:939
u盘头戴式耳机怎么连接安卓手机 发布:2024-05-22 07:25:30 浏览:603
pc换图脚本 发布:2024-05-22 07:24:00 浏览:111
辅助脚本是怎么制作的 发布:2024-05-22 07:15:04 浏览:686
怎么在服务器中找人 发布:2024-05-22 07:06:23 浏览:104
ftp建立win10 发布:2024-05-22 06:27:02 浏览:845
苹果怎么改安卓系统 发布:2024-05-22 06:21:21 浏览:20
飞儿精品教程解压密码 发布:2024-05-22 06:21:17 浏览:903