android客户端设置界面开发实例

我们在开发软件的时候,都会填一个功能就是设置,查看很多软件大多数都是圆角形式,最近在帮一个客户做直播客户端也要添加一个设置界面,因此分享一下制作过程先看一下效果图(上面还包含一个头,但是里面含有客户信息,就给去掉了)


效果图就如上面的,其实也就是LinearLayout加上圆角,每一行用RelativeLayout布局,由于还要点击的时候改变背景颜色,所以我同时实现了OnClickListener和OnTouchListener,其中OnClickListener来实现功能,OnTouchListener来实现变色。先看代码吧。

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff2f2f2f"
    android:orientation="vertical" >

    <include
        android:id="@id/actionbar"
        style="@style/ActionBar"
        layout="@layout/top_item" >
    </include>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dip"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:gravity="center_vertical"
            android:text="@string/setting_soft"
            android:textSize="25sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/nor_concor"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@id/share_tssv_p"
                android:layout_width="match_parent"
                android:layout_height="40dip"
                android:background="@drawable/nor_up_concor"
                android:orientation="horizontal" >

                <TextView
                    android:id="@id/share_tssv"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dip"
                    android:gravity="center_vertical"
                    android:text="@string/setting_soft_share"
                    android:textSize="15sp" />

                <ImageView
                    android:layout_width="20dip"
                    android:layout_height="20dip"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dip"
                    android:background="@drawable/setting_click"
                    android:contentDescription="@string/app_name" />
            </RelativeLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:background="@drawable/sc_line"
                android:contentDescription="@string/app_name" />

            <RelativeLayout
                android:id="@id/clear_cache_p"
                android:layout_width="match_parent"
                android:layout_height="40dip"
                android:orientation="horizontal" >

                <TextView
                    android:id="@id/clear_cache"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dip"
                    android:gravity="center_vertical"
                    android:text="@string/setting_soft_clear_cache"
                    android:textSize="15sp" />

                <ImageView
                    android:layout_width="20dip"
                    android:layout_height="20dip"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dip"
                    android:background="@drawable/setting_click"
                    android:contentDescription="@string/app_name" />
            </RelativeLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:background="@drawable/sc_line"
                android:contentDescription="@string/app_name" />

            <RelativeLayout
                android:id="@id/soft_feedback_p"
                android:layout_width="match_parent"
                android:layout_height="40dip"
                android:orientation="horizontal" >

                <TextView
                    android:id="@id/soft_feedback"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dip"
                    android:gravity="center_vertical"
                    android:text="@string/setting_soft_feedback"
                    android:textSize="15sp" />

                <ImageView
                    android:layout_width="20dip"
                    android:layout_height="20dip"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dip"
                    android:background="@drawable/setting_click"
                    android:contentDescription="@string/app_name" />
            </RelativeLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:background="@drawable/sc_line"
                android:contentDescription="@string/app_name" />

            <RelativeLayout
                android:id="@id/contack_me_p"
                android:layout_width="match_parent"
                android:layout_height="40dip"
                android:orientation="horizontal" >

                <TextView
                    android:id="@id/contack_me"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:layout_marginLeft="5dip"
                    android:text="@string/setting_soft_contact"
                    android:textSize="15sp" />

                <ImageView
                    android:layout_width="20dip"
                    android:layout_height="20dip"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="5dip"
                    android:background="@drawable/setting_click"
                    android:contentDescription="@string/app_name" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dip"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:gravity="center_vertical"
            android:text="@string/setting_other"
            android:textSize="25sp" />

        <RelativeLayout
            android:id="@id/quality_application_p"
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:background="@drawable/nor_concor"
            android:orientation="horizontal" >

            <TextView
                android:id="@id/quality_application"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dip"
                android:gravity="center_vertical"
                android:text="@string/setting_other_quality_applications"
                android:textSize="15sp" />

            <ImageView
                android:layout_width="20dip"
                android:layout_height="20dip"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="5dip"
                android:background="@drawable/setting_click"
                android:contentDescription="@string/app_name" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>
由于设置界面只是一部分,我并不是使用的Activity而是使用的Fragment

public class Setting_Page extends Fragment implements OnClickListener, OnTouchListener{

	private View settingView;
	private TextView shareSoft, clearCache, feedback, contack_me, qulity_apps;
	private RelativeLayout shaeSoftLayout, clearCacheLayout, feedbackLayout, contack_meLayout, qulity_appsLayout;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		settingView = inflater.inflate(R.layout.setting_page, null);
		settingView.findViewById(R.id.home_top_bg).setBackgroundResource(
				R.drawable.setting_logo);
		return settingView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		shareSoft = (TextView)settingView.findViewById(R.id.share_tssv);
		shaeSoftLayout = (RelativeLayout)settingView.findViewById(R.id.share_tssv_p);
		shareSoft.setOnClickListener(this);
		shareSoft.setOnTouchListener(this);
		clearCache = (TextView)settingView.findViewById(R.id.clear_cache);
		clearCacheLayout = (RelativeLayout)settingView.findViewById(R.id.clear_cache_p);
		clearCache.setOnClickListener(this);
		clearCache.setOnTouchListener(this);
		feedback = (TextView)settingView.findViewById(R.id.soft_feedback);
		feedbackLayout = (RelativeLayout)settingView.findViewById(R.id.soft_feedback_p);
		feedback.setOnClickListener(this);
		feedback.setOnTouchListener(this);
		contack_me = (TextView)settingView.findViewById(R.id.contack_me);
		contack_meLayout = (RelativeLayout)settingView.findViewById(R.id.contack_me_p);
		contack_me.setOnClickListener(this);
		contack_me.setOnTouchListener(this);
		qulity_apps = (TextView)settingView.findViewById(R.id.quality_application);
		qulity_appsLayout = (RelativeLayout)settingView.findViewById(R.id.quality_application_p);
		qulity_apps.setOnClickListener(this);
		qulity_apps.setOnTouchListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.share_tssv:
			ShareTSSV();
			break;
		case R.id.clear_cache:
			AppLog.e("clear_cache");
			break;
		case R.id.soft_feedback:
			AppLog.e("soft_feedback");
			break;
		case R.id.contack_me:
			AppLog.e("contack_me");
			break;
		case R.id.quality_application:
			AppLog.e("quality_application");
			break;
		}
	}
	
	
	public void ShareTSSV(){
		Intent shareIntent = new Intent(Intent.ACTION_SEND);
		shareIntent.setType("text/plain");
		shareIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.share_subject);
		shareIntent.putExtra(Intent.EXTRA_TEXT, R.string.share_text);
		shareIntent.putExtra(Intent.EXTRA_TITLE, R.string.share_title);
		shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_select)));
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.share_tssv:
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				shaeSoftLayout.setBackgroundResource(R.drawable.press_up_concor);
				break;
			case MotionEvent.ACTION_UP:
				shaeSoftLayout.setBackgroundResource(R.drawable.nor_up_concor);
				break;
			}
			break;
		case R.id.clear_cache:
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				clearCacheLayout.setBackgroundColor(getResources().getColor(R.color.papayawhip));
				break;
			case MotionEvent.ACTION_UP:
				clearCacheLayout.setBackgroundColor(getResources().getColor(R.color.turnk));
				break;
			}
			break;
		case R.id.soft_feedback:
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				feedbackLayout.setBackgroundColor(getResources().getColor(R.color.papayawhip));
				break;
			case MotionEvent.ACTION_UP:
				feedbackLayout.setBackgroundColor(getResources().getColor(R.color.turnk));
				break;
			}
			break;
		case R.id.contack_me:
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				contack_meLayout.setBackgroundResource(R.drawable.press_down_concor);
				break;
			case MotionEvent.ACTION_UP:
				contack_meLayout.setBackgroundResource(R.drawable.nor_down_concor);
				break;
			}
			break;
		case R.id.quality_application:
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				qulity_appsLayout.setBackgroundResource(R.drawable.press_concor);
				break;
			case MotionEvent.ACTION_UP:
				qulity_appsLayout.setBackgroundResource(R.drawable.nor_concor);
				break;
			}
			break;
		}
		return false;
	}
}


其中里面涉及到的资源布局如下:

nor_concor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#ffffffff" />

    <corners
        android:bottomLeftRadius="10.0dip"
        android:bottomRightRadius="10.0dip"
        android:topLeftRadius="10.0dip"
        android:topRightRadius="10.0dip" />

</shape>

press_concor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFEFD5" />

    <corners
        android:bottomLeftRadius="10.0dip"
        android:bottomRightRadius="10.0dip"
        android:topLeftRadius="10.0dip"
        android:topRightRadius="10.0dip" />

</shape>

nor_up_concor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#00000000" />

    <corners
        android:topLeftRadius="10.0dip"
        android:topRightRadius="10.0dip" />
</shape>

press_up_concor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFEFD5" />

    <corners
        android:topLeftRadius="10.0dip"
        android:topRightRadius="10.0dip" />
</shape>


nor_down_concor.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#00000000" />

    <corners
        android:bottomLeftRadius="10.0dip"
        android:bottomRightRadius="10.0dip" />

</shape>


press_down_concor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFEFD5" />

    <corners
        android:bottomLeftRadius="10.0dip"
        android:bottomRightRadius="10.0dip"/>

</shape>

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 好的,这是你可以使用的步骤来实现一个Android FTP客户端: 1. 使用Android Studio创建一个新的Android项目。 2. 在build.gradle文件中添加对Apache Commons Net库的依赖,它是实现FTP客户端所必需的库。 dependencies { implementation 'commons-net:commons-net:3.7' } 3. 在您的主活动中添加一些用于连接到FTP服务器的代码。您可以使用FTPClient类来连接和操作FTP服务器。 FTPClient ftpClient = new FTPClient(); ftpClient.connect(server, port); ftpClient.login(username, password); 4. 现在,您可以使用FTPClient实例来执行各种操作,如上传文件、下载文件、创建目录等。 例如,要上传文件,您可以使用以下代码: InputStream inputStream = new FileInputStream(localFile); ftpClient.storeFile(serverFile, inputStream); inputStream.close(); 5. 最后,记得在退出应用程序时断开与FTP服务器的连接。 ftpClient.logout(); ftpClient.disconnect(); 希望这对你有帮助! ### 回答2: 要实现一个Android的FTP客户端,可以按照以下步骤进行: 1. 导入FTP类库:首先需要在Android项目中导入FTP的类库,例如Apache Commons Net库或者Android FTP库。这些类库提供了FTP客户端所需的功能和方法。 2. 创建FTP连接:在Android应用中,可以使用FTP客户端类来创建一个FTP连接对象。通过指定FTP服务器的IP地址、用户名和密码来建立连接。 3. 执行FTP操作:一旦连接建立成功,就可以执行FTP操作。这些操作可以包括上传文件、下载文件、删除文件、创建文件夹等。可以通过调用FTP客户端对象的相应方法来执行这些操作。 4. 实现文件传输:要上传或下载文件,可以使用FTP客户端提供的方法。要上传文件,可以将本地文件的路径作为参数,通过调用相应方法将文件传输到FTP服务器上。要下载文件,可以指定要下载的文件路径和下载的本地路径,然后调用相应方法来实现。 5. 错误处理:在实现FTP客户端时,还需要考虑错误处理。例如,在连接或文件传输过程中可能会发生网络异常或服务器错误。可以使用try-catch语句来捕获这些异常,并根据需要采取相应的处理措施。 6. 界面设计:为了更好地与用户交互,可以设计一个用户界面来显示FTP操作的进度和结果。可以使用Android中提供的布局和小部件来创建用户界面,并更新进度和显示结果。 以上是一个基本的Android实现FTP客户端的步骤。根据具体的需求,还可以进行更多的功能扩展,例如实现断点续传、支持多线程下载等。 ### 回答3: 实现一个Android上的FTP客户端可以通过以下步骤: 1. 添加权限:在AndroidManifest.xml文件中添加网络权限,以便应用程序可以进行网络通信。 2. 创建FTP连接类:创建FTP连接类,用于建立和管理与FTP服务器的连接。该类应该包括连接到FTP服务器的方法、断开连接的方法以及上传和下载文件的方法。 3. 用户界面设计:创建一个用户界面,以便用户可以输入FTP服务器的地址、用户名和密码。还可以添加其他的选项,例如显示已上传和已下载的文件列表。 4. 连接到FTP服务器:当用户点击连接按钮时,读取用户输入的FTP服务器地址、用户名和密码,并使用FTP连接类中的方法连接到服务器上。 5. 上传文件:创建一个文件选择器,以便用户可以选择要上传的文件。当用户选择文件后,使用FTP连接类中的上传文件的方法将文件上传到服务器上。 6. 下载文件:显示服务器上的文件列表,当用户选择要下载的文件时,使用FTP连接类中的下载文件的方法将文件下载到设备上。 7. 错误处理:在连接到服务器、上传和下载文件过程中,需要添加错误处理机制,以便在发生错误时提示用户出现问题,并提供重新连接或重新上传/下载的选项。 8. UI界面优化:可以添加进度条显示上传和下载的进度,增加用户体验。 9. 测试和调试:编译并运行应用程序,测试连接、上传和下载功能。在出现错误时,使用日志输出和调试工具进行调试。 10. 发布应用程序:完成开发后,可以使用Android工具生成应用程序的安装文件,并发布到应用商店供用户下载使用。 以上就是大致的步骤,根据实际需求还可以对功能进行扩展和优化,比如实现断点续传、多线程并行传输等功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值