2015-06-10 134 views
0

我按照工具欄教程,當我試圖在其下面添加編輯文本,然後在我的物理設備上運行它時,我無法輸入任何文本。我不知道我做錯了什麼。我將自定義文本顏色應用於apptheme中的編輯文本,但我懷疑問題是因爲這個原因。無法在編輯文本視圖中輸入文本

這是我的XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".MainActivity"> 
<include 
    android:id="@+id/toolbar" 
    layout="@layout/tool_bar"/> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText" 
    android:layout_below="@+id/toolbar" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:textSize="30sp" 
    android:hint="enter text"/> 

,這就是我在我的style.xml文件:

sources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/ColorPrimary</item> 
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item> 
    <item name="android:editTextStyle">@style/CustomEditText</item> 
</style> 
<style name="CustomEditText"> 
    <item name="android:textColor">#ab42</item> 
</style> 

這是我的主要活動:

public class MainActivity extends AppCompatActivity { 
private Toolbar mToolbar; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mToolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(mToolbar); 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.menu_main,menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 
    if(id == R.id.action_search){ 
     Toast.makeText(this,"SEARCH",Toast.LENGTH_LONG).show(); 
    }else if(id == R.id.action_user){ 
     Toast.makeText(this,"User",Toast.LENGTH_LONG).show(); 
    }else{ 
     Toast.makeText(this,"Overflow",Toast.LENGTH_LONG).show(); 
    } 

    return super.onOptionsItemSelected(item); 
} 

enter image description here

回答

1

您的代碼似乎沒問題。

我不知道,如果它會幫助,但你可以嘗試更新您的佈局代碼如下:

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText" 
    android:layout_below="@+id/toolbar" 
    android:textSize="30sp" 
    android:hint="enter text"/> 

我已經刪除layout_alignParentLeftlayout_alignParentStart屬性和layout_width的變化值從wrap_contentmatch_parent

這只是我的猜測。

此外,您可以明確定義EditTexteditable

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText" 
    android:layout_below="@+id/toolbar" 
    android:textSize="30sp"   
    android:hint="enter text" 
    android:editable="true"/> 
1

我發現了問題,我自己。我忘了從主題的一些基本編輯文本中繼承下來:

<style name="CustomEditText" parent="Widget.AppCompat.EditText"> 
    <item name="android:textColor">#ab42</item> 
</style> 
相關問題