2017-06-17 251 views
1

我想改變列表視圖的文本大小,但我不擅長編碼更改的ListView TEXTSIZE爲Android

我想盡一切辦法,但它不可能

我想成爲大TEXTSIZE請幫我

[http://imgur.com/a/IPc2u][1]

這裏我的代碼;

Activicty.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="-24dp" 
android:textSize="26sp" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.haziranonalti.MainActivity"> 


<ListView 
    android:layout_width="match_parent" 
    android:id="@+id/Listview" 
    android:headerDividersEnabled="false" 
    android:layout_height="match_parent" 
    android:dividerHeight="4px" 
    android:padding="0dp" 
    android:textSize="26sp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 


MainActivity.java

public class MainActivity extends AppCompatActivity { 
ListView listView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    listView = (ListView) findViewById(R.id.Listview); 
    final String[] values = new String[]{"Deneme", "Deneme2", "Deneme3","Deneme4","Deneme5","Deneme6"}; 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.activity_list_item, android.R.id.text1, values); 
      listView.setAdapter(adapter); 
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 
      if (position == 0) { 
       Intent myintent = new Intent(view.getContext(), Main2Activity.class); 
       startActivityForResult(myintent, 0); 
      } 
      if (position == 1) { 
       Intent myintent = new Intent(view.getContext(), Main3Activity.class); 
       startActivityForResult(myintent, 1); 
      } 
      if (position == 2) { 
       Intent myintent = new Intent(view.getContext(), Main4Activity.class); 
       startActivityForResult(myintent, 2); 
      } 
      if (position == 3) { 
       Intent myintent = new Intent(view.getContext(), Main5Activity.class); 
       startActivityForResult(myintent, 3); 
      } 
      if (position == 4) { 
       Intent myintent = new Intent(view.getContext(), Main6Activity.class); 
       startActivityForResult(myintent, 4); 
      } 
      if (position == 5) { 
       Intent myintent = new Intent(view.getContext(), Main7Activity.class); 
       startActivityForResult(myintent, 5); 
+0

'android.R.layout.activity_list_item'爲'android.R.layout.simple_list_item_1'是夠嗎? – Akis

+0

是的,這是對我來說足夠。非常感謝你保存我的屁股。 –

+0

後來生病回來更多的細節和方式在任何規模的設置字體大小來回答你想要 – Akis

回答

2

變化的佈局參數simple_list_item_1

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
android.R.layout.simple_list_item_1, android.R.id.text1, values); 

或者,您可以創建在佈局目錄中的新佈局文件,並用這個來代替:

custom_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:textSize="26dp" /> 

,然後使用自定義佈局:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
android.R.layout.custom_layout, android.R.id.text1, values); 
如果你改變
+0

非常感謝。這比我的舊版本更好。順便說一句我還有一個問題,我如何添加搜索視圖。 –