전체글

JSP :: 3주차

2017. 9. 30. 15:22


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>

<form action="CalculatorResult.jsp" method="post">

<input type="text" name ="firstnum"><p>

<input type="text" name ="secondnum"><p>

<input type="submit" value = "전송">

</form>


</body>

</html>

<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>


<%

String firstnum = request.getParameter("firstnum");

String secondnum = request.getParameter("secondnum");

out.print(firstnum + " + ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) +Integer.parseInt(secondnum));

%>

</body>

</html>




String 클래스함수인 parseInt를 통해 문자열을 int형으로 형변환



<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>

<form action="CalculatorResult2.jsp" method="post">

<input type="text" name ="firstnum"><p>

<input type="text" name ="secondnum"><p>

<input type="submit" value = "전송">

</form>


</body>

</html>


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>


<%

String firstnum = request.getParameter("firstnum");

String secondnum = request.getParameter("secondnum");

out.print(firstnum + " + ");

out.print(secondnum + " = ");

out.print(Float.parseFloat(firstnum) +Float.parseFloat(secondnum));

%>

</body>

</html>









<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>


<form action="CalculatorResult3.jsp" method="post">

<input type="hidden" name = "cal" value = "+">

<input type="text" name ="firstnum"> +

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="CalculatorResult3.jsp" method="post">

<input type="hidden" name = "cal" value = "-">

<input type="text" name ="firstnum"> -

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="CalculatorResult3.jsp" method="post">

<input type="hidden" name = "cal" value = "*">

<input type="text" name ="firstnum"> *

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="CalculatorResult3.jsp" method="post">

<input type="hidden" name = "cal" value = "/">

<input type="text" name ="firstnum"> /

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


</body>

</html>



<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>


<%

String cal = request.getParameter("cal");

String firstnum = request.getParameter("firstnum");

String secondnum = request.getParameter("secondnum");

switch(cal){

case("+"):

out.print(firstnum + " + ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) + Integer.parseInt(secondnum));

break;

case("-"):

out.print(firstnum + " - ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) - Integer.parseInt(secondnum));

break;

case("*"):

out.print(firstnum + " * ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) * Integer.parseInt(secondnum));

break;

case("/"):

out.print(firstnum + " / ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) / Integer.parseInt(secondnum));

break;

}

%>

</body>

</html>


Input type 중 hidden 변수에 값을 대입시켜 어떤 Form을 전송시켰는지 구별한다.



<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>계산기</h1>


<form action="Calculator4.jsp" method="post">

<input type="hidden" name = "cal" value = "+">

<input type="text" name ="firstnum"> +

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="Calculator4.jsp" method="post">

<input type="hidden" name = "cal" value = "-">

<input type="text" name ="firstnum"> -

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="Calculator4.jsp" method="post">

<input type="hidden" name = "cal" value = "*">

<input type="text" name ="firstnum"> *

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p><p>


<form action="Calculator4.jsp" method="post">

<input type="hidden" name = "cal" value = "/">

<input type="text" name ="firstnum"> /

<input type="text" name ="secondnum">

<input type="submit" value = "전송">

</form>


<p>


<%

String cal = request.getParameter("cal");

String firstnum = request.getParameter("firstnum");

String secondnum = request.getParameter("secondnum");

if ( cal != null && firstnum != null && secondnum != null){

switch(cal){

case("+"):

out.print(firstnum + " + ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) + Integer.parseInt(secondnum));

break;

case("-"):

out.print(firstnum + " - ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) - Integer.parseInt(secondnum));

break;

case("*"):

out.print(firstnum + " * ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) * Integer.parseInt(secondnum));

break;

case("/"):

out.print(firstnum + " / ");

out.print(secondnum + " = ");

out.print(Integer.parseInt(firstnum) / Integer.parseInt(secondnum));

break;

}

}


%>


</body>

</html>



한 페이지 내에서 사칙연산을 하는 코드로, 초기에 값이 없으므로 이러한 경우를 판단해 코드 실행을 막아 에러를 방지한다.


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<h1>Select 테스트</h1>

<form action="Test001.jsp" method="get">

<select name = "_portal">

<option value="네이버">네이버</option>

<option value="다음">다음</option>

<option value="구글">구글</option>

</select>

<p>

<input type="submit" value="전송">

</form>

</body>

</html>





<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%= "선택된 포탈 : " + request.getParameter("_portal")%>

</body>

</html>



쉽다.

'JSP' 카테고리의 다른 글

JSP :: 2주차  (0) 2017.09.30
JSP :: 1주차  (0) 2017.09.30

JSP :: 2주차

2017. 9. 30. 15:18


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<form action="FormTest002.jsp" method="get">

ID : <input type="text" name="_id"><p>

PW : <input type="password" name="_pwd"><p>

<input type="submit" value="전송">

</form>

</body>

</html>






<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>


<%

String id = request.getParameter("_id");

String pwd = request.getParameter("_pwd");

out.println(" ID : " + id);

out.println("<p>");

out.println(" pwd : " + pwd);

%>


</body>

</html>



Form 태그를 이용해서 정보를 전달하는 과정








--------------------------------------------------------------------------------------------


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

회원 등록



<form action="MemberResult.jsp" method="post">

성명 : <input type="text" name="_name"><p>

아이디 : <input type="text" name="_id"><p>

암호 : <input type="password" name="_pwd"><p>

전화번호 : <input type="text" name="_hpnum"><p>



종교 : <input type="radio" name="_religion" value="기독교">기독교

<input type="radio" name="_religion" value="천주교">천주교

<input type="radio" name="_religion" value="불교">불교<p>



관심분야 : <input type="checkbox" name="inter" value="게임" />게임

<input type="checkbox" name="inter" value="쇼핑" />쇼핑

<input type="checkbox" name="inter" value="교육" />교육<p>



<input type="submit" value="등록">

<input type="reset" value="취소">

</form>

</body>

</html>









<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

request.setCharacterEncoding("EUC-KR");

String id = request.getParameter("_id");

String pwd = request.getParameter("_pwd");

String _name = request.getParameter("_name");

String _hpnum = request.getParameter("_hpnum");

String _religion = request.getParameter("_religion");

String[] inter = request.getParameterValues("inter");



out.println("회원 등록 완료 <p>");



out.println(" 성명 : " + _name);

out.println("<p>");

out.println(" 아이디 : " + id);

out.println("<p>");

out.println(" 암호 : " + pwd);

out.println("<p>");

out.println(" 전화번호 : " + _hpnum);

out.println("<p>");

out.println(" 종교 : " + _religion);

out.println("<p>");

out.println(" 관심분야 : ");



for (int i = 0; i < inter.length ; i++){

out.println(inter[i]);

}



out.println("<p>");

%>

</body>

</html>



체크박스의 경우 여러 파라미터를 전달할 수 있기때문에 String 배열형으로 값을 전달받는다.






---------------------------------------------------------------------------------------------------------------------------




<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

String str = "Hello, Weclome to JSP world! Lets Go!";

out.println("문자열 길이 : " + str.length() + "<p>");

out.println("JSP 문자 위치 : " + str.indexOf("JSP")+ "<p>");

out.println("소문자 변환 : " + str.toLowerCase() + "<p>");

out.println("대문자 변환 : " + str.toUpperCase() + "<p>");


%>

</body>

</html>



자바 DOC을 통해 필요한 함수를 찾는 연습을 해보자




'JSP' 카테고리의 다른 글

JSP :: 3주차  (0) 2017.09.30
JSP :: 1주차  (0) 2017.09.30

JSP :: 1주차

2017. 9. 30. 15:12


<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

String a = "인하공전 ";

String b = "컴퓨터 시스템과";

out.println(a + b + " 홍길동");

%>

</body>

</html>


스크립트릿 <% %> : 자바 코딩이 가능하다.




<%@ page language="java" contentType="text/html; charset=EUC-KR"

   pageEncoding="EUC-KR"%>

<%@ page import = "java.util.Date" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>


<script language = "Javascript">

function viewDate(){

var d = new Date();

document.FormName.Date.value = (d.getYear()+1900)+"년"+(d.getMonth()+1)+"월"+d.getDate()+"일";

}

</script>

<body>


<%

Date d = new Date();

out.println((d.getYear()+1900)+"년"+(d.getMonth()+1)+"월"+d.getDate()+"일");

%>


<Form Name = "FormName">

Local Date : <Input Type = "Text" Name = "Date">

<Input Type = "Button" Value = "Call Local date" onClick="viewDate()">

</Form>

</body>

</html>



자바스크립트 또한 가능하다.



'JSP' 카테고리의 다른 글

JSP :: 3주차  (0) 2017.09.30
JSP :: 2주차  (0) 2017.09.30

여행 :: 후쿠오카 여행

2017. 8. 19. 19:50

1.

로션 사려고 드러그스토어에감. 마약아님. 점원한테 로션어딨냐고 하니까 손잡고 끌고감

보니까 로션있음

근데 주변에 콘돔이랑 여성용품이랑 같이있음

글씨보니까 make love. 그렇다. 러브젤이다.

세수하는 시늉하면서 로션어디있냐고 하니까 빵터지면서 내가 원하는 로션이 있는 곳으로 안내해줌.




2.

드러그 스토어 나오니까 21시30분임. 숙소 체크인 마감시간을 확인하니 22시까지였다.

ㅈ됐음을 직감하고 뜀박질을 시작함. 결국 숙소가 있는 골목에 접근.

그리고 사람들한테 숙소를 물어봤으나 모두 모르쇠로 일관함.

주택가였는데 주변 주민조차도 모를만큼 닥템급 존재감으로 추정.왔던 길을 되돌아 가면서 무언가를 보고 깨달음. 

군대에 가면 정보통신대대라고 나무를 파낸 간판과 비스무리한 것을 자세히 보고 읽어보니 숙소 이름과 일치한다는 사실. 

결국 체크인 마감시간 내에 도착할 수 있었다.


저녁을 굶었기 때문에 패밀리 마트에 감. 

일본 친구들이 추천해준 화미치키라는 일본판 넓적다리를 먹어보려했으나 밤이라 그런지 텅텅 비어있었음.

평소 편의점 샌드위치를 좋아하던 나는 샌드위치와 쥬스를 마심. 참고로 일본인들은 일반 음식점의 경우 장사를 빨리 마침.



2일차 벳부~



3.

하카타 역에서 벳푸 역으로 가기 위해 jr 수퍼소닉 기차표를 구입하고 탑승.

파란색 열차였고, 색깔보다 중요한 건 가격이었음. 한화 5만원 정도이며, 이는 내가 구청에서 알바했을 때 일당 수준임. 

아무튼 수퍼 소닉이라는 이름에 걸맞게 '나 잘달리지?' 라며 증명하는 듯한 기차를 지나 벳푸역에 도착. 

손을 세척하는 온천수와 이상한 동작의 아재 동상이 나를 반김.






4.

숙소찾기에 나섬. 어제와 같이 주택가에 위치해 있기때문에 힘들것을 예상했으나 예상 밖, 상상? 이상! 이었음

3연타 라임에 맞춰 같은 골목을 세 번 확인했기때문. 결국 숙소를 발견. 

그 숙소는 2층 건물 중에서 2층에 자리하고 있었지만 간판이 없었고, 더불어 1층은 장례식장이었다. 

그래서 '저기는 아니겠지' 라고 판단을 했었던 것. 그리고 하늘엔 까마귀 소리가 울려퍼지고 있었다. 

살짝 소름이었지만 그 날 밤에 게스트 하우스 주인들이 치킨과 계란치즈말이를 만들어줘서 맛있게 먹었다. 

그리고 보드게임을 한 판 하며 하루를 마무리. 게스트 하우스 주인은 20대 대학생과 18살 고등학생이었다.





집 고양이 발견. 네코



벳부 야경.




3일차 유후인,기타큐슈 ~



5. 

일본의 버스기사분들은 친절하다. 좌/우 회전, 정지, 출발할 경우 방송을하며, 승객이 하차할 때까지 기다려준다.

마치 군대 사단장 운전과 오버랩되는 느낌이다.


6.

사실 유후인은 볼 게 별로 없는 것 같다. 물론 내가 잘 몰라서 그런 것일 수 있다. 유명한 건 온천인데 더워서 가질 않았으니

그럴 수 밖에.












7.

기타큐슈의 철도 박물관 견학. 괜히 갔다.







8.

고쿠라 성과 고쿠라 성 정원, 견학하기 괜찮다.

고쿠라 성 내부에는 기타큐슈의 역사를 알 수 있는 동영상을 틀어주는 등 볼 거리가 풍부하다.





9. 

된장라멘과 치킨, 매우 맛있었다. 라면은 요리라기보단 cheap한 느낌이었는데 이 라멘을 맛 보고는 진짜 요리라고 느꼈다.

치킨또한 기름에 바싹 튀긴 후 간장 소스를 입힌 다음, 그 위에 타르타르소스를 얹어 엄청난 조미료 맛으로 나를 매혹했다.

MainActivity.java



public class MainActivity extends ActionBarActivity{

Button btn[] = new Button[3];
ViewPager viewPager = null;
int p=0; //페이지번호
int v=1; //화면 전환 뱡향

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

viewPager = (ViewPager)findViewById(R.id.viewPager);
MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());

viewPager.setAdapter(adapter);
}
}


activity_main.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--
<Button
android:id="@+id/btn_a"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A"
style="@style/Widget.AppCompat.ActionButton"/>
<Button
android:id="@+id/btn_b"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="B"
style="@style/Widget.AppCompat.ActionButton"/>
<Button
android:id="@+id/btn_c"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C"
style="@style/Widget.AppCompat.ActionButton"/>
-->
</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


</LinearLayout>



fragmentA.java


public class FragmentA extends Fragment{

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

return inflater.inflate(R.layout.fragment_a, container, false);
}
}



fragment_a.xml

<?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:orientation="vertical"
android:background="#5DA4BE">
</LinearLayout>


마찬가지로 fragmentB.java fragmentC.java fragment_b.xml fragment_c.xml 생성


public class MainActivity extends ActionBarActivity implements View.OnClickListener {

Button btn[] = new Button[3];
ViewPager viewPager = null;
Handler handler = null;
int p=0; //페이지번호
int v=1; //화면 전환 뱡향

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//viewPager
viewPager = (ViewPager)findViewById(R.id.viewPager);
MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());

viewPager.setAdapter(adapter);

btn[0] = (Button)findViewById(R.id.btn_a);
btn[1] = (Button)findViewById(R.id.btn_b);
btn[2] = (Button)findViewById(R.id.btn_c);

for(int i=0;i<btn.length; i++){
btn[i].setOnClickListener(this);
}

}

@Override
public void onClick(View v) {

switch(v.getId()){
case R.id.btn_a:
viewPager.setCurrentItem(0);
Toast.makeText(this,"A버튼", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_b:
viewPager.setCurrentItem(1);
Toast.makeText(this,"B버튼", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_c:
viewPager.setCurrentItem(2);
Toast.makeText(this,"C버튼", Toast.LENGTH_SHORT).show();
break;
default:
break;

}

}
}


위와 같이 View.OnClickListener 인터페이스를 상속받아 onClick 메소드를 통해 모든 클릭 이벤트를 일괄 처리

안드로이드 :: API 에러

2017. 6. 26. 16:08



위와같이 Call requires API level 16 (currentmin is 14): android.view.View#setBackground more

어쩌구 농락을 한다.




이럴땐 gradle 을 손보자.




들어가서



defaultConfig {
applicationId "com.fractalwrench.androidbootstrap.sample"

minSdkVersion Integer.parseInt(MIN_SDK_INT)
targetSdkVersion Integer.parseInt(TARGET_SDK_INT)
versionCode = Integer.parseInt(VERSION_CODE)
versionName = VERSION_NAME
}


변경해주자


defaultConfig {
applicationId "com.fractalwrench.androidbootstrap.sample"

minSdkVersion 16
targetSdkVersion Integer.parseInt(TARGET_SDK_INT)
versionCode = Integer.parseInt(VERSION_CODE)
versionName = VERSION_NAME
}



SDK 버전쪽을 변경해주면 끝

안드로이드에서 xml은 레이아웃을 담당한다. 그리고 xml 안에 xml을 넣는 경우가 있다.


예를 들어 버튼이나 텍스트뷰의 모서리 모양을 둥글게 하고 싶을 때, drawable에 둥근 모양을 설정하는 xml파일을 넣는다.


그리고 레이아웃을 구성하는 xml에서 파일을 불러와 둥근 모서리를 구현한다. 


안드로이드 자체 xml 에서는 둥근 모양을 설정할 수 없었기 때문에 이런 비효율적인 방법으로 구현할 수 밖에 없었다.




그리고 오늘 나의 경우는 둥근 모서리의 레이아웃을 구현하되, 특정 레이아웃을 클릭하면 둥근 모서리의 레이아웃의 색상도 변경해야 했다.




firstboard.xml


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

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

<!-- 테두리
<stroke android:width="10dip" android:color="#5DA4BE" />
-->
<corners android:bottomLeftRadius="20dip"
android:bottomRightRadius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>



secondboard.xml


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

<solid android:color="#5DA4BE"/>

<!-- 테두리
<stroke android:width="10dip" android:color="#5DA4BE" />
-->
<corners android:bottomLeftRadius="20dip"
android:bottomRightRadius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>




activity_main.xml 중 일부분


<LinearLayout
android:id="@+id/bottomboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="@drawable/firstboard"
android:orientation="vertical">
</LinearLayout>



HomeActivity.java


findViewById(R.id.firstlayout).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

findViewById(R.id.bottomboard).setBackground(
getResources().getDrawable(R.drawable.firstboard)
);
}
});



레이아웃 클릭 시, 색상변경

1. 레이아웃 activity_intro.xml 추가


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="인트로" />

</LinearLayout>



2. 자바 IntroActivity 추가



package com.fractalwrench.androidbootstrap.sample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

/**
* Created by chickenNcola on 2017. 6. 25..
*/

public class IntroActivity extends Activity {
Handler handler;//핸들러 선언

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
handler= new Handler();
handler.postDelayed(mrun, 2000); // 시간 2초 딜레이
}

Runnable mrun = new Runnable(){
@Override
public void run(){
Intent HomeActivity = new Intent(IntroActivity.this, HomeActivity.class); //인텐트 생성(현 액티비티, 새로 실행할 액티비티)
startActivity(HomeActivity);
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
//overridePendingTransition : 서서히 사라지는 효과
}
};
//인트로 중에 뒤로가기를 누를 경우 핸들러를 끊어버려 아무일 없게 만드는 부분
//미 설정시 인트로 중 뒤로가기를 누르면 인트로 후에 홈화면이 나옴.
@Override
public void onBackPressed(){
super.onBackPressed();
handler.removeCallbacks(mrun);
}
}


3.  manifasts 파일에 코드 추가


<!-- 인트로 -->
<activity
android:name=".IntroActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->

<item name="colorPrimaryDark">#A1CDE1</item>
<item name="colorPrimary">#5DA4BE</item>


</style>



Styles.xml 에 위의 코드 추가

16진수 색상값만 원하는 값으로 변경해주면 됨



colorPrimaryDark : 상태바 ( 최상단 시간이랑 LTE, 와이파이 보여주는 바 )

colorPrimary : 타이틀바 ( 앱 이름 나오는 바 )



결과



                       코드 추가 전                                                            코드 추가 후

                                          





+ Recent posts