2016-08-20 4 views
0

я хотел бы знать, где это проблема, потому что я получаю эту ошибку все время:Как я могу добавить Time Picker с правильным их приложением и с соответствующим стилем?

Отсутствующие стили. Правильная ли тема выбрана для этого макета? Используйте поле со списком Тема над макетом, чтобы выбрать другой макет, или исправьте ссылки стиля стилей.

Не удалось найти тему ресурс? Attr/colorAccent для текущей темы Не удалось найти '? Attr/colorAccent' в текущей теме.

Main_activity:

package dz.timepicker; 
import java.util.Calendar; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.TextView; 
import android.widget.TimePicker; 

public class MainActivity extends Activity { 
    private TimePicker timePicker1; 
    private TextView time; 
    private Calendar calendar; 
    private String format = ""; 

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

     timePicker1 = (TimePicker) findViewById(R.id.timePicker1); 
     time = (TextView) findViewById(R.id.tv1); 
     calendar = Calendar.getInstance(); 

     int hour = calendar.get(Calendar.HOUR_OF_DAY); 
     int min = calendar.get(Calendar.MINUTE); 
     showTime(hour, min); 
    } 

    public void setTime(View view) { 
     int hour = timePicker1.getCurrentHour(); 
     int min = timePicker1.getCurrentMinute(); 
     showTime(hour, min); 
    } 

    public void showTime(int hour, int min) { 
     if (hour == 0) { 
     hour += 12; 
     format = "AM"; 
     } 
     else if (hour == 12) { 
     format = "PM"; 
     } else if (hour > 12) { 
     hour -= 12; 
     format = "PM"; 
     } else { 
     format = "AM"; 
     } 
     time.setText(new StringBuilder().append(hour).append(" : ").append(min) 
     .append(" ").append(format)); 
    } 


} 

main_activity.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" > 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="@string/time_pick" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<Button 
    android:id="@+id/set_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="180dp" 
    android:onClick="setTime" 
    android:text="@string/time_save" /> 

<TimePicker 
    android:id="@+id/timePicker1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/set_button" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="24dp" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignStart="@+id/timePicker1" 
    android:layout_alignTop="@+id/set_button" 
    android:layout_marginTop="67dp" 
    android:text="@string/time_current" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TextView 
    android:id="@+id/tv1" 
    android:labelFor="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView3" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="50dp" 
    android:text="@string/time_selected" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

String.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<string name="app_name">TimePicker</string> 
    <string name="action_settings">Settings</string> 
    <string name="time_picker_example">Time Picker Example</string> 
    <string name="time_pick">Pick the time and press save button</string> 
    <string name="time_save">Save</string> 
    <string name="time_selected"></string> 
    <string name="time_current">The Time is:</string> 
</resources> 

Style.xm л:

<resources> 

    <!-- 
     Base application theme, dependent on API level. This theme is replaced 
     by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 

    --> 
    <style name="AppBaseTheme" parent="android:Theme.Light"> 
     <!-- 
      Theme customizations available in newer API levels can go in 
      res/values-vXX/styles.xml, while customizations related to 
      backward-compatibility can go here. 
     --> 
    </style> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 

</resources> 

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="dz.timepicker" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="23" 
     android:targetSdkVersion="23" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 

ответ

1

Ну, android:Theme.Light тема.

?attr/colorAccent - это признак.

И ваша ошибка говорит, что тема не содержит этого атрибута.

Его можно добавить в ваш AppBaseTheme. Не стесняйтесь использовать любой цвет

<style name="AppBaseTheme" parent="android:Theme.Light"> 
    <item name="colorAccent">#E91E63</item> 
</style> 
+0

Работаю с затмением, когда я их выбираю. Возникла ли ошибка? –

+0

Eclipse - это просто среда, где вы пишете код. Это не вызывает проблемы. Вы добавляете эту строку в 'style.xml' внутри' AppBaseTheme'? –

+0

да, я могу, может быть, моя графическая карта не поддерживает эту тему. У меня есть семейство наборов микросхем семейства Intel (R) 4 Series Express с Intel CORE 2 DUO. –

 Смежные вопросы

  • Нет связанных вопросов^_^