보기의 모서리를 둥글게하고 런타임에 내용을 기반으로보기의 색을 변경하고 싶습니다.프로그래밍 방식으로 모서리를 둥글게하고 임의의 배경색을 설정하는 방법
TextView v = new TextView(context);
v.setText(tagsList.get(i));
if(i%2 == 0){
v.setBackgroundColor(Color.RED);
}else{
v.setBackgroundColor(Color.BLUE);
}
v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
v.setPadding(twoDP, twoDP, twoDP, twoDP);
v.setBackgroundResource(R.drawable.tags_rounded_corners);
드로어 블을 설정하고 색상이 겹치기를 바랬지 만 그럴 수는 없습니다. 어느 것이 든 내가 두 번째로 실행하는 것은 결과적인 배경이다.
런타임까지 배경색이 결정되지 않는다는 것을 염두에두고 프로그래밍 방식으로이보기를 만들 수 있습니까?
편집 : 이제 테스트를 위해 빨강과 파랑 사이를 바꿀뿐입니다. 나중에 사용자가 색상을 선택할 수있게됩니다.
편집 :
tags_rounded_corners.xml 대신 setBackgroundColor
의
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>
물론 배경색과 배경 이미지가 서로 대체됩니다. 무엇을 성취하려고합니까? 'tags_rounded_corners'는 무엇입니까? –
더 많은 코드를 보여줄 수 있습니까? 그것은 괜찮아 보이는 그래서 당신이 listView 종류를 사용하거나 기존 textview 재사용 할 수도 있습니다. – Chansuk
확인해보십시오. http://www.gadgetsaint.com/tips/rounded-corners-views-layouts-android/#.WPZ2QVN97BI – ASP